Commit 93142598 authored by Andi Sardina's avatar Andi Sardina
Browse files

Setting the tab icon after the tab has been added.

parent 3696a327
......@@ -611,14 +611,15 @@ void MainShellTest::testOpenInvalidFiles_data()
QTest::addColumn<QString>("options");
QString options = ShellUtils::serializeOptions( false, false, false, false, false, QString(), QString() );
QUrl validFile = ShellUtils::urlFromArg( QStringLiteral( KDESRCDIR "data/file2.pdf" ), ShellUtils::qfileExistFunc(), QString() );
QUrl validFile1 = ShellUtils::urlFromArg( QStringLiteral( KDESRCDIR "data/file1.pdf" ), ShellUtils::qfileExistFunc(), QString() );
QUrl validFile2 = ShellUtils::urlFromArg( QStringLiteral( KDESRCDIR "data/file2.pdf" ), ShellUtils::qfileExistFunc(), QString() );
QUrl invalidFile = ShellUtils::urlFromArg( QStringLiteral( KDESRCDIR "data/non-existing-doc.pdf" ), ShellUtils::qfileExistFunc(), QString() );
QList<QUrl> firstCase { invalidFile, validFile };
QList<QUrl> secondCase { validFile, invalidFile };
QList<QUrl> firstCase { invalidFile, validFile1, validFile2 };
QList<QUrl> secondCase { validFile1, validFile2, invalidFile };
QTest::newRow( "opening the invalid file first" ) << firstCase << options;
QTest::newRow( "opening the valid file first" ) << secondCase << options;
QTest::newRow( "opening the valids file first" ) << secondCase << options;
}
void MainShellTest::testOpenInvalidFiles()
......@@ -656,9 +657,14 @@ void MainShellTest::testOpenInvalidFiles()
QList<QUrl> recentFiles = shell->m_recent->urls();
QVERIFY( shell->m_tabs.size() == 1 );
QVERIFY( recentFiles.size() == 1 );
QVERIFY( recentFiles.first().toString().contains( QStringLiteral( "data/file2.pdf" ) ) );
QVERIFY( shell->m_tabs.size() == 2 );
QVERIFY( shell->m_tabWidget->tabBar()->isVisible() );
QVERIFY( ! shell->m_tabWidget->tabIcon(0).isNull() );
QVERIFY( ! shell->m_tabWidget->tabIcon(1).isNull() );
QVERIFY( recentFiles.size() == 2 );
}
void MainShellTest::testMiddleButtonCloseUndo()
......
......@@ -1095,6 +1095,11 @@ bool Part::openNewFilesInTabs() const
return Okular::Settings::self()->shellOpenFileInTabs();
}
QMimeType Part::documentMimeType()
{
return m_documentMimeType;
}
void Part::slotHandleActivatedSourceReference(const QString& absFileName, int line, int col, bool *handled)
{
emit openSourceReference( absFileName, line, col );
......@@ -1571,6 +1576,7 @@ bool Part::openFile()
}
bool canSearch = m_document->supportsSearching();
m_documentMimeType = mime;
emit mimeTypeChanged( mime );
// update one-time actions
......
......@@ -146,6 +146,8 @@ class OKULARPART_EXPORT Part : public KParts::ReadWritePart, public Okular::Docu
void setShowSourceLocationsGraphically(bool show) override;
bool openNewFilesInTabs() const override;
QMimeType documentMimeType();
public Q_SLOTS: // dbus
Q_SCRIPTABLE Q_NOREPLY void goToPage(uint page) override;
Q_SCRIPTABLE Q_NOREPLY void openDocument( const QString &doc );
......@@ -416,6 +418,9 @@ class OKULARPART_EXPORT Part : public KParts::ReadWritePart, public Okular::Docu
// String to search in document startup
QString m_textToFindOnOpen;
// Mime Type of the document opened by this part.
QMimeType m_documentMimeType;
private Q_SLOTS:
void slotAnnotationPreferences();
void slotHandleActivatedSourceReference(const QString& absFileName, int line, int col, bool *handled);
......
......@@ -18,7 +18,7 @@ ecm_add_app_icon(okular_SRCS ICONS ${ICONS_SRCS})
add_executable(okular ${okular_SRCS})
target_link_libraries(okular KF5::Parts KF5::WindowSystem KF5::Crash)
target_link_libraries(okular KF5::Parts KF5::WindowSystem KF5::Crash okularpart)
if(TARGET KF5::Activities)
target_compile_definitions(okular PUBLIC -DWITH_KACTIVITIES=1)
......
......@@ -48,6 +48,7 @@
#include <KUrlMimeData>
#include <KLocalizedString>
#include <KSharedConfig>
#include <part.h>
#include <KIO/Global>
#ifdef WITH_KACTIVITIES
#include <KActivities/ResourceInstance>
......@@ -302,6 +303,7 @@ void Shell::openUrl( const QUrl & url, const QString &serializedOptions )
m_activityResource->setUri( url );
#endif
m_recent->addUrl( url );
setTabIcon(activeTab, activePart);
}
else
{
......@@ -673,7 +675,6 @@ void Shell::closeTab( int tab )
void Shell::openNewTab( const QUrl& url, const QString &serializedOptions )
{
const int newIndex = m_tabs.size();
// Make new part
......@@ -684,7 +685,6 @@ void Shell::openNewTab( const QUrl& url, const QString &serializedOptions )
applyOptionsToPart(part, serializedOptions);
int previousActiveTab = m_tabWidget->currentIndex();
setActiveTab( m_tabs.size() - 1 );
if( part->openUrl(url) )
{
......@@ -699,6 +699,8 @@ void Shell::openNewTab( const QUrl& url, const QString &serializedOptions )
m_prevTabAction->setEnabled( true );
}
setTabIcon(newIndex, part);
setActiveTab( newIndex );
m_recent->addUrl( url );
}
else
......@@ -728,7 +730,6 @@ void Shell::connectPart( QObject* part )
connect( this, SIGNAL(moveSplitter(int)), part, SLOT(moveSplitter(int)) );
connect( part, SIGNAL(enablePrintAction(bool)), this, SLOT(setPrintEnabled(bool)));
connect( part, SIGNAL(enableCloseAction(bool)), this, SLOT(setCloseEnabled(bool)));
connect( part, SIGNAL(mimeTypeChanged(QMimeType)), this, SLOT(setTabIcon(QMimeType)));
connect( part, SIGNAL(urlsDropped(QList<QUrl>)), this, SLOT(handleDroppedUrls(QList<QUrl>)) );
connect( part, SIGNAL(fitWindowToPage(QSize,QSize)), this, SLOT(slotFitWindowToPage(QSize,QSize)) );
}
......@@ -799,13 +800,16 @@ void Shell::undoCloseTab()
openUrl(lastTabUrl);
}
void Shell::setTabIcon( const QMimeType& mimeType )
void Shell::setTabIcon( int tabIndex, KParts::ReadWritePart *part )
{
int i = findTabIndex( sender() );
if( i != -1 )
Okular::Part* okularPart = static_cast<Okular::Part*>(part);
QMimeType mimeType = okularPart->documentMimeType();
if ( mimeType.isValid() )
{
m_tabWidget->setTabIcon( i, QIcon::fromTheme(mimeType.iconName()) );
m_tabWidget->setTabIcon( tabIndex, QIcon::fromTheme(mimeType.iconName()) );
}
}
int Shell::findTabIndex( QObject* sender )
......@@ -820,6 +824,7 @@ int Shell::findTabIndex( QObject* sender )
return -1;
}
void Shell::handleDroppedUrls( const QList<QUrl>& urls )
{
for ( const QUrl &url : urls )
......
......@@ -117,7 +117,6 @@ private Q_SLOTS:
void print();
void setPrintEnabled( bool enabled );
void setCloseEnabled( bool enabled );
void setTabIcon(const QMimeType& mimeType );
void handleDroppedUrls( const QList<QUrl>& urls );
// Tab event handlers
......@@ -141,6 +140,7 @@ private:
void applyOptionsToPart( QObject* part, const QString &serializedOptions );
void connectPart( QObject* part );
int findTabIndex( QObject* sender );
void setTabIcon(int tabIndex, KParts::ReadWritePart* part);
private:
bool eventFilter(QObject *obj, QEvent *event) override;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment