1bb02e0acSNicolas Bonnefon /* 2093a1bf6SNicolas Bonnefon * Copyright (C) 2009, 2010, 2011, 2013, 2014 Nicolas Bonnefon and other contributors 3bb02e0acSNicolas Bonnefon * 4bb02e0acSNicolas Bonnefon * This file is part of glogg. 5bb02e0acSNicolas Bonnefon * 6bb02e0acSNicolas Bonnefon * glogg is free software: you can redistribute it and/or modify 7bb02e0acSNicolas Bonnefon * it under the terms of the GNU General Public License as published by 8bb02e0acSNicolas Bonnefon * the Free Software Foundation, either version 3 of the License, or 9bb02e0acSNicolas Bonnefon * (at your option) any later version. 10bb02e0acSNicolas Bonnefon * 11bb02e0acSNicolas Bonnefon * glogg is distributed in the hope that it will be useful, 12bb02e0acSNicolas Bonnefon * but WITHOUT ANY WARRANTY; without even the implied warranty of 13bb02e0acSNicolas Bonnefon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14bb02e0acSNicolas Bonnefon * GNU General Public License for more details. 15bb02e0acSNicolas Bonnefon * 16bb02e0acSNicolas Bonnefon * You should have received a copy of the GNU General Public License 17bb02e0acSNicolas Bonnefon * along with glogg. If not, see <http://www.gnu.org/licenses/>. 18bb02e0acSNicolas Bonnefon */ 19bb02e0acSNicolas Bonnefon 20bb02e0acSNicolas Bonnefon // This file implements MainWindow. It is responsible for creating and 21bb02e0acSNicolas Bonnefon // managing the menus, the toolbar, and the CrawlerWidget. It also 22bb02e0acSNicolas Bonnefon // load/save the settings on opening/closing of the app 23bb02e0acSNicolas Bonnefon 24bb02e0acSNicolas Bonnefon #include <iostream> 251b5e406eSNicolas Bonnefon #include <cassert> 26eb6a8f99SNicolas Bonnefon 27eb6a8f99SNicolas Bonnefon #include <QAction> 28eb6a8f99SNicolas Bonnefon #include <QDesktopWidget> 29eb6a8f99SNicolas Bonnefon #include <QMenuBar> 30eb6a8f99SNicolas Bonnefon #include <QToolBar> 31eb6a8f99SNicolas Bonnefon #include <QFileInfo> 32eb6a8f99SNicolas Bonnefon #include <QFileDialog> 33eb6a8f99SNicolas Bonnefon #include <QClipboard> 34eb6a8f99SNicolas Bonnefon #include <QMessageBox> 35eb6a8f99SNicolas Bonnefon #include <QCloseEvent> 36eb6a8f99SNicolas Bonnefon #include <QDragEnterEvent> 37eb6a8f99SNicolas Bonnefon #include <QMimeData> 38eb6a8f99SNicolas Bonnefon #include <QUrl> 39bb02e0acSNicolas Bonnefon 40bb02e0acSNicolas Bonnefon #include "log.h" 41bb02e0acSNicolas Bonnefon 42bb02e0acSNicolas Bonnefon #include "mainwindow.h" 43bb02e0acSNicolas Bonnefon 44bb02e0acSNicolas Bonnefon #include "sessioninfo.h" 45bb02e0acSNicolas Bonnefon #include "recentfiles.h" 46bb02e0acSNicolas Bonnefon #include "crawlerwidget.h" 47bb02e0acSNicolas Bonnefon #include "filtersdialog.h" 48bb02e0acSNicolas Bonnefon #include "optionsdialog.h" 49bb02e0acSNicolas Bonnefon #include "persistentinfo.h" 50bb02e0acSNicolas Bonnefon #include "menuactiontooltipbehavior.h" 51093a1bf6SNicolas Bonnefon #include "tabbedcrawlerwidget.h" 5209aff35dSNicolas Bonnefon #include "externalcom.h" 53bb02e0acSNicolas Bonnefon 540a90ca6aSNicolas Bonnefon // Returns the size in human readable format 550a90ca6aSNicolas Bonnefon static QString readableSize( qint64 size ); 560a90ca6aSNicolas Bonnefon 5709aff35dSNicolas Bonnefon MainWindow::MainWindow( std::unique_ptr<Session> session, 5809aff35dSNicolas Bonnefon std::shared_ptr<ExternalCommunicator> external_communicator ) : 59d96f3f21SNicolas Bonnefon session_( std::move( session ) ), 6009aff35dSNicolas Bonnefon externalCommunicator_( external_communicator ), 6111582726SNicolas Bonnefon recentFiles_( Persistent<RecentFiles>( "recentFiles" ) ), 62313a820fSNicolas Bonnefon mainIcon_(), 6327ddfd3aSNicolas Bonnefon signalMux_(), 64b423cd88SNicolas Bonnefon quickFindMux_( session_->getQuickFindPattern() ), 65093a1bf6SNicolas Bonnefon mainTabWidget_() 66431d01deSNicolas Bonnefon #ifdef GLOGG_SUPPORTS_VERSION_CHECKING 67431d01deSNicolas Bonnefon ,versionChecker_() 68431d01deSNicolas Bonnefon #endif 69bb02e0acSNicolas Bonnefon { 70bb02e0acSNicolas Bonnefon createActions(); 71bb02e0acSNicolas Bonnefon createMenus(); 72bb02e0acSNicolas Bonnefon createToolBars(); 73bb02e0acSNicolas Bonnefon // createStatusBar(); 74bb02e0acSNicolas Bonnefon 75bb02e0acSNicolas Bonnefon setAcceptDrops( true ); 76bb02e0acSNicolas Bonnefon 77bb02e0acSNicolas Bonnefon // Default geometry 78bb02e0acSNicolas Bonnefon const QRect geometry = QApplication::desktop()->availableGeometry( this ); 79bb02e0acSNicolas Bonnefon setGeometry( geometry.x() + 20, geometry.y() + 40, 80bb02e0acSNicolas Bonnefon geometry.width() - 140, geometry.height() - 140 ); 81bb02e0acSNicolas Bonnefon 82bb02e0acSNicolas Bonnefon mainIcon_.addFile( ":/images/hicolor/16x16/glogg.png" ); 83bb02e0acSNicolas Bonnefon mainIcon_.addFile( ":/images/hicolor/24x24/glogg.png" ); 84bb02e0acSNicolas Bonnefon mainIcon_.addFile( ":/images/hicolor/32x32/glogg.png" ); 85bb02e0acSNicolas Bonnefon mainIcon_.addFile( ":/images/hicolor/48x48/glogg.png" ); 86bb02e0acSNicolas Bonnefon 87bb02e0acSNicolas Bonnefon setWindowIcon( mainIcon_ ); 88f0708ca8SNicolas Bonnefon 890a90ca6aSNicolas Bonnefon readSettings(); 900a90ca6aSNicolas Bonnefon 9127ddfd3aSNicolas Bonnefon // Connect the signals to the mux (they will be forwarded to the 9227ddfd3aSNicolas Bonnefon // "current" crawlerwidget 9327ddfd3aSNicolas Bonnefon 9427ddfd3aSNicolas Bonnefon // Send actions to the crawlerwidget 9527ddfd3aSNicolas Bonnefon signalMux_.connect( this, SIGNAL( followSet( bool ) ), 9627ddfd3aSNicolas Bonnefon SIGNAL( followSet( bool ) ) ); 9727ddfd3aSNicolas Bonnefon signalMux_.connect( this, SIGNAL( optionsChanged() ), 9827ddfd3aSNicolas Bonnefon SLOT( applyConfiguration() ) ); 998570d8d2SNicolas Bonnefon signalMux_.connect( this, SIGNAL( enteringQuickFind() ), 1008570d8d2SNicolas Bonnefon SLOT( enteringQuickFind() ) ); 1018570d8d2SNicolas Bonnefon signalMux_.connect( &quickFindWidget_, SIGNAL( close() ), 1028570d8d2SNicolas Bonnefon SLOT( exitingQuickFind() ) ); 10327ddfd3aSNicolas Bonnefon 10427ddfd3aSNicolas Bonnefon // Actions from the CrawlerWidget 105b297d2f4SNicolas Bonnefon signalMux_.connect( SIGNAL( followModeChanged( bool ) ), 106b297d2f4SNicolas Bonnefon this, SLOT( changeFollowMode( bool ) ) ); 10727ddfd3aSNicolas Bonnefon signalMux_.connect( SIGNAL( updateLineNumber( int ) ), 10827ddfd3aSNicolas Bonnefon this, SLOT( lineNumberHandler( int ) ) ); 10927ddfd3aSNicolas Bonnefon 11027ddfd3aSNicolas Bonnefon // Register for progress status bar 11127ddfd3aSNicolas Bonnefon signalMux_.connect( SIGNAL( loadingProgressed( int ) ), 11227ddfd3aSNicolas Bonnefon this, SLOT( updateLoadingProgress( int ) ) ); 113812146a8SNicolas Bonnefon signalMux_.connect( SIGNAL( loadingFinished( LoadingStatus ) ), 114812146a8SNicolas Bonnefon this, SLOT( handleLoadingFinished( LoadingStatus ) ) ); 11527ddfd3aSNicolas Bonnefon 116f688be2eSNicolas Bonnefon // Register for checkbox changes 117f688be2eSNicolas Bonnefon signalMux_.connect( SIGNAL( searchRefreshChanged( int ) ), 118f688be2eSNicolas Bonnefon this, SLOT( handleSearchRefreshChanged( int ) ) ); 119f688be2eSNicolas Bonnefon signalMux_.connect( SIGNAL( ignoreCaseChanged( int ) ), 120f688be2eSNicolas Bonnefon this, SLOT( handleIgnoreCaseChanged( int ) ) ); 121f688be2eSNicolas Bonnefon 122cdd89779SNicolas Bonnefon // Configure the main tabbed widget 123093a1bf6SNicolas Bonnefon mainTabWidget_.setDocumentMode( true ); 124cdd89779SNicolas Bonnefon mainTabWidget_.setMovable( true ); 125093a1bf6SNicolas Bonnefon //mainTabWidget_.setTabShape( QTabWidget::Triangular ); 126cdd89779SNicolas Bonnefon mainTabWidget_.setTabsClosable( true ); 127cdd89779SNicolas Bonnefon 128cdd89779SNicolas Bonnefon connect( &mainTabWidget_, SIGNAL( tabCloseRequested( int ) ), 129cdd89779SNicolas Bonnefon this, SLOT( closeTab( int ) ) ); 130ee835f33SNicolas Bonnefon connect( &mainTabWidget_, SIGNAL( currentChanged( int ) ), 131ee835f33SNicolas Bonnefon this, SLOT( currentTabChanged( int ) ) ); 132b423cd88SNicolas Bonnefon 133b423cd88SNicolas Bonnefon // Establish the QuickFindWidget and mux ( to send requests from the 134b423cd88SNicolas Bonnefon // QFWidget to the right window ) 135b423cd88SNicolas Bonnefon connect( &quickFindWidget_, SIGNAL( patternConfirmed( const QString&, bool ) ), 136b423cd88SNicolas Bonnefon &quickFindMux_, SLOT( confirmPattern( const QString&, bool ) ) ); 137b423cd88SNicolas Bonnefon connect( &quickFindWidget_, SIGNAL( patternUpdated( const QString&, bool ) ), 138b423cd88SNicolas Bonnefon &quickFindMux_, SLOT( setNewPattern( const QString&, bool ) ) ); 139b423cd88SNicolas Bonnefon connect( &quickFindWidget_, SIGNAL( cancelSearch() ), 140b423cd88SNicolas Bonnefon &quickFindMux_, SLOT( cancelSearch() ) ); 141b423cd88SNicolas Bonnefon connect( &quickFindWidget_, SIGNAL( searchForward() ), 142b423cd88SNicolas Bonnefon &quickFindMux_, SLOT( searchForward() ) ); 143b423cd88SNicolas Bonnefon connect( &quickFindWidget_, SIGNAL( searchBackward() ), 144b423cd88SNicolas Bonnefon &quickFindMux_, SLOT( searchBackward() ) ); 145b423cd88SNicolas Bonnefon connect( &quickFindWidget_, SIGNAL( searchNext() ), 146b423cd88SNicolas Bonnefon &quickFindMux_, SLOT( searchNext() ) ); 147b423cd88SNicolas Bonnefon 148b423cd88SNicolas Bonnefon // QuickFind changes coming from the views 1498570d8d2SNicolas Bonnefon connect( &quickFindMux_, SIGNAL( patternChanged( const QString& ) ), 150b423cd88SNicolas Bonnefon this, SLOT( changeQFPattern( const QString& ) ) ); 151b423cd88SNicolas Bonnefon connect( &quickFindMux_, SIGNAL( notify( const QFNotification& ) ), 152b423cd88SNicolas Bonnefon &quickFindWidget_, SLOT( notify( const QFNotification& ) ) ); 153b423cd88SNicolas Bonnefon connect( &quickFindMux_, SIGNAL( clearNotification() ), 154b423cd88SNicolas Bonnefon &quickFindWidget_, SLOT( clearNotification() ) ); 155b423cd88SNicolas Bonnefon 15609aff35dSNicolas Bonnefon // Actions from external instances 15709aff35dSNicolas Bonnefon connect( externalCommunicator_.get(), SIGNAL( loadFile( const QString& ) ), 15809aff35dSNicolas Bonnefon this, SLOT( loadFileNonInteractive( const QString& ) ) ); 159ba1adacfSNicolas Bonnefon connect( qApp, SIGNAL( loadFile( const QString& ) ), 160ba1adacfSNicolas Bonnefon this, SLOT( loadFileNonInteractive( const QString& ) ) ); 16109aff35dSNicolas Bonnefon 162f109b95bSNicolas Bonnefon #ifdef GLOGG_SUPPORTS_VERSION_CHECKING 163460de700SNicolas Bonnefon // Version checker notification 164460de700SNicolas Bonnefon connect( &versionChecker_, SIGNAL( newVersionFound( const QString& ) ), 165460de700SNicolas Bonnefon this, SLOT( newVersionNotification( const QString& ) ) ); 166f109b95bSNicolas Bonnefon #endif 167460de700SNicolas Bonnefon 168b423cd88SNicolas Bonnefon // Construct the QuickFind bar 169b423cd88SNicolas Bonnefon quickFindWidget_.hide(); 170b423cd88SNicolas Bonnefon 171b423cd88SNicolas Bonnefon QWidget* central_widget = new QWidget(); 172b423cd88SNicolas Bonnefon QVBoxLayout* main_layout = new QVBoxLayout(); 173548acbf6SNicolas Bonnefon main_layout->setContentsMargins( 0, 0, 0, 0 ); 174b423cd88SNicolas Bonnefon main_layout->addWidget( &mainTabWidget_ ); 175b423cd88SNicolas Bonnefon main_layout->addWidget( &quickFindWidget_ ); 176b423cd88SNicolas Bonnefon central_widget->setLayout( main_layout ); 177b423cd88SNicolas Bonnefon 178b423cd88SNicolas Bonnefon setCentralWidget( central_widget ); 179bb02e0acSNicolas Bonnefon } 180bb02e0acSNicolas Bonnefon 181d1edc4fcSNicolas Bonnefon void MainWindow::reloadGeometry() 1828964a9adSNicolas Bonnefon { 183b76966a6SNicolas Bonnefon QByteArray geometry; 184b76966a6SNicolas Bonnefon 185b76966a6SNicolas Bonnefon session_->storedGeometry( &geometry ); 186b76966a6SNicolas Bonnefon restoreGeometry( geometry ); 187d1edc4fcSNicolas Bonnefon } 188b76966a6SNicolas Bonnefon 189d1edc4fcSNicolas Bonnefon void MainWindow::reloadSession() 190d1edc4fcSNicolas Bonnefon { 1918964a9adSNicolas Bonnefon int current_file_index = -1; 1928964a9adSNicolas Bonnefon 1938964a9adSNicolas Bonnefon for ( auto open_file: session_->restore( 1948964a9adSNicolas Bonnefon []() { return new CrawlerWidget(); }, 1958964a9adSNicolas Bonnefon ¤t_file_index ) ) 1968964a9adSNicolas Bonnefon { 1978964a9adSNicolas Bonnefon QString file_name = { open_file.first.c_str() }; 1988964a9adSNicolas Bonnefon CrawlerWidget* crawler_widget = dynamic_cast<CrawlerWidget*>( 1998964a9adSNicolas Bonnefon open_file.second ); 2008964a9adSNicolas Bonnefon 2018964a9adSNicolas Bonnefon assert( crawler_widget ); 2028964a9adSNicolas Bonnefon 2038964a9adSNicolas Bonnefon mainTabWidget_.addTab( crawler_widget, strippedName( file_name ) ); 2048964a9adSNicolas Bonnefon } 2058964a9adSNicolas Bonnefon 2068964a9adSNicolas Bonnefon if ( current_file_index >= 0 ) 2078964a9adSNicolas Bonnefon mainTabWidget_.setCurrentIndex( current_file_index ); 2088964a9adSNicolas Bonnefon } 2098964a9adSNicolas Bonnefon 210bb02e0acSNicolas Bonnefon void MainWindow::loadInitialFile( QString fileName ) 211bb02e0acSNicolas Bonnefon { 212bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "loadInitialFile"; 213bb02e0acSNicolas Bonnefon 214bb02e0acSNicolas Bonnefon // Is there a file passed as argument? 215bb02e0acSNicolas Bonnefon if ( !fileName.isEmpty() ) 216bb02e0acSNicolas Bonnefon loadFile( fileName ); 217bb02e0acSNicolas Bonnefon } 218bb02e0acSNicolas Bonnefon 2198a9275b2SNicolas Bonnefon void MainWindow::startBackgroundTasks() 2208a9275b2SNicolas Bonnefon { 2218a9275b2SNicolas Bonnefon LOG(logDEBUG) << "startBackgroundTasks"; 222431d01deSNicolas Bonnefon 223431d01deSNicolas Bonnefon #ifdef GLOGG_SUPPORTS_VERSION_CHECKING 224431d01deSNicolas Bonnefon versionChecker_.startCheck(); 225431d01deSNicolas Bonnefon #endif 2268a9275b2SNicolas Bonnefon } 2278a9275b2SNicolas Bonnefon 228bb02e0acSNicolas Bonnefon // 229bb02e0acSNicolas Bonnefon // Private functions 230bb02e0acSNicolas Bonnefon // 231bb02e0acSNicolas Bonnefon 2325fa25391SNicolas Bonnefon const MainWindow::EncodingList MainWindow::encoding_list[] = { 2335fa25391SNicolas Bonnefon { "&Auto" }, 2345fa25391SNicolas Bonnefon { "ASCII / &ISO-8859-1" }, 2355fa25391SNicolas Bonnefon { "&UTF-8" }, 2364a4a124eSNicolas Bonnefon { "UTF-16LE" }, 2374a4a124eSNicolas Bonnefon { "UTF-16BE" }, 238f25e35f2SNicolas Bonnefon { "CP1251" }, 239f25e35f2SNicolas Bonnefon { "CP1252" }, 240*048334c9SSeerauber { "&Big5" }, 241*048334c9SSeerauber { "&GB18030 / GB2312" }, 242*048334c9SSeerauber { "&Shift_JIS" }, 243*048334c9SSeerauber { "&KOI8-R" } 2445fa25391SNicolas Bonnefon }; 2455fa25391SNicolas Bonnefon 246bb02e0acSNicolas Bonnefon // Menu actions 247bb02e0acSNicolas Bonnefon void MainWindow::createActions() 248bb02e0acSNicolas Bonnefon { 24911582726SNicolas Bonnefon std::shared_ptr<Configuration> config = 25011582726SNicolas Bonnefon Persistent<Configuration>( "settings" ); 251bb02e0acSNicolas Bonnefon 252bb02e0acSNicolas Bonnefon openAction = new QAction(tr("&Open..."), this); 253bb02e0acSNicolas Bonnefon openAction->setShortcut(QKeySequence::Open); 254c633ced3SNicolas Bonnefon openAction->setIcon( QIcon( ":/images/open14.png" ) ); 255bb02e0acSNicolas Bonnefon openAction->setStatusTip(tr("Open a file")); 256bb02e0acSNicolas Bonnefon connect(openAction, SIGNAL(triggered()), this, SLOT(open())); 257bb02e0acSNicolas Bonnefon 25863dc3514SGustav Andersson closeAction = new QAction(tr("&Close"), this); 25904325d43SGustav Andersson closeAction->setShortcut(tr("Ctrl+W")); 26063dc3514SGustav Andersson closeAction->setStatusTip(tr("Close document")); 26163dc3514SGustav Andersson connect(closeAction, SIGNAL(triggered()), this, SLOT(closeTab())); 26263dc3514SGustav Andersson 26363dc3514SGustav Andersson closeAllAction = new QAction(tr("Close &All"), this); 26463dc3514SGustav Andersson closeAllAction->setStatusTip(tr("Close all documents")); 26563dc3514SGustav Andersson connect(closeAllAction, SIGNAL(triggered()), this, SLOT(closeAll())); 26663dc3514SGustav Andersson 267bb02e0acSNicolas Bonnefon // Recent files 268bb02e0acSNicolas Bonnefon for (int i = 0; i < MaxRecentFiles; ++i) { 269bb02e0acSNicolas Bonnefon recentFileActions[i] = new QAction(this); 270bb02e0acSNicolas Bonnefon recentFileActions[i]->setVisible(false); 271bb02e0acSNicolas Bonnefon connect(recentFileActions[i], SIGNAL(triggered()), 272bb02e0acSNicolas Bonnefon this, SLOT(openRecentFile())); 273bb02e0acSNicolas Bonnefon } 274bb02e0acSNicolas Bonnefon 275bb02e0acSNicolas Bonnefon exitAction = new QAction(tr("E&xit"), this); 276bb02e0acSNicolas Bonnefon exitAction->setShortcut(tr("Ctrl+Q")); 277bb02e0acSNicolas Bonnefon exitAction->setStatusTip(tr("Exit the application")); 278bb02e0acSNicolas Bonnefon connect( exitAction, SIGNAL(triggered()), this, SLOT(close()) ); 279bb02e0acSNicolas Bonnefon 280bb02e0acSNicolas Bonnefon copyAction = new QAction(tr("&Copy"), this); 281bb02e0acSNicolas Bonnefon copyAction->setShortcut(QKeySequence::Copy); 282bb02e0acSNicolas Bonnefon copyAction->setStatusTip(tr("Copy the selection")); 283bb02e0acSNicolas Bonnefon connect( copyAction, SIGNAL(triggered()), this, SLOT(copy()) ); 284bb02e0acSNicolas Bonnefon 285bb02e0acSNicolas Bonnefon selectAllAction = new QAction(tr("Select &All"), this); 286bb02e0acSNicolas Bonnefon selectAllAction->setShortcut(tr("Ctrl+A")); 287bb02e0acSNicolas Bonnefon selectAllAction->setStatusTip(tr("Select all the text")); 288bb02e0acSNicolas Bonnefon connect( selectAllAction, SIGNAL(triggered()), 289bb02e0acSNicolas Bonnefon this, SLOT( selectAll() ) ); 290bb02e0acSNicolas Bonnefon 291bb02e0acSNicolas Bonnefon findAction = new QAction(tr("&Find..."), this); 292bb02e0acSNicolas Bonnefon findAction->setShortcut(QKeySequence::Find); 293bb02e0acSNicolas Bonnefon findAction->setStatusTip(tr("Find the text")); 294bb02e0acSNicolas Bonnefon connect( findAction, SIGNAL(triggered()), 295bb02e0acSNicolas Bonnefon this, SLOT( find() ) ); 296bb02e0acSNicolas Bonnefon 297bb02e0acSNicolas Bonnefon overviewVisibleAction = new QAction( tr("Matches &overview"), this ); 298bb02e0acSNicolas Bonnefon overviewVisibleAction->setCheckable( true ); 29911582726SNicolas Bonnefon overviewVisibleAction->setChecked( config->isOverviewVisible() ); 300bb02e0acSNicolas Bonnefon connect( overviewVisibleAction, SIGNAL( toggled( bool ) ), 301bb02e0acSNicolas Bonnefon this, SLOT( toggleOverviewVisibility( bool )) ); 302bb02e0acSNicolas Bonnefon 303bb02e0acSNicolas Bonnefon lineNumbersVisibleInMainAction = 304bb02e0acSNicolas Bonnefon new QAction( tr("Line &numbers in main view"), this ); 305bb02e0acSNicolas Bonnefon lineNumbersVisibleInMainAction->setCheckable( true ); 30611582726SNicolas Bonnefon lineNumbersVisibleInMainAction->setChecked( config->mainLineNumbersVisible() ); 307bb02e0acSNicolas Bonnefon connect( lineNumbersVisibleInMainAction, SIGNAL( toggled( bool ) ), 308bb02e0acSNicolas Bonnefon this, SLOT( toggleMainLineNumbersVisibility( bool )) ); 309bb02e0acSNicolas Bonnefon 310bb02e0acSNicolas Bonnefon lineNumbersVisibleInFilteredAction = 311bb02e0acSNicolas Bonnefon new QAction( tr("Line &numbers in filtered view"), this ); 312bb02e0acSNicolas Bonnefon lineNumbersVisibleInFilteredAction->setCheckable( true ); 31311582726SNicolas Bonnefon lineNumbersVisibleInFilteredAction->setChecked( config->filteredLineNumbersVisible() ); 314bb02e0acSNicolas Bonnefon connect( lineNumbersVisibleInFilteredAction, SIGNAL( toggled( bool ) ), 315bb02e0acSNicolas Bonnefon this, SLOT( toggleFilteredLineNumbersVisibility( bool )) ); 316bb02e0acSNicolas Bonnefon 317bb02e0acSNicolas Bonnefon followAction = new QAction( tr("&Follow File"), this ); 318bb02e0acSNicolas Bonnefon followAction->setShortcut(Qt::Key_F); 319bb02e0acSNicolas Bonnefon followAction->setCheckable(true); 320bb02e0acSNicolas Bonnefon connect( followAction, SIGNAL(toggled( bool )), 321bb02e0acSNicolas Bonnefon this, SIGNAL(followSet( bool )) ); 322bb02e0acSNicolas Bonnefon 323bb02e0acSNicolas Bonnefon reloadAction = new QAction( tr("&Reload"), this ); 324bb02e0acSNicolas Bonnefon reloadAction->setShortcut(QKeySequence::Refresh); 325c633ced3SNicolas Bonnefon reloadAction->setIcon( QIcon(":/images/reload14.png") ); 32632e44cfdSNicolas Bonnefon signalMux_.connect( reloadAction, SIGNAL(triggered()), SLOT(reload()) ); 327bb02e0acSNicolas Bonnefon 328bb02e0acSNicolas Bonnefon stopAction = new QAction( tr("&Stop"), this ); 329c633ced3SNicolas Bonnefon stopAction->setIcon( QIcon(":/images/stop14.png") ); 3307875bde2SNicolas Bonnefon stopAction->setEnabled( true ); 3317847299cSNicolas Bonnefon signalMux_.connect( stopAction, SIGNAL(triggered()), SLOT(stopLoading()) ); 332bb02e0acSNicolas Bonnefon 333bb02e0acSNicolas Bonnefon filtersAction = new QAction(tr("&Filters..."), this); 334bb02e0acSNicolas Bonnefon filtersAction->setStatusTip(tr("Show the Filters box")); 335bb02e0acSNicolas Bonnefon connect( filtersAction, SIGNAL(triggered()), this, SLOT(filters()) ); 336bb02e0acSNicolas Bonnefon 337bb02e0acSNicolas Bonnefon optionsAction = new QAction(tr("&Options..."), this); 338bb02e0acSNicolas Bonnefon optionsAction->setStatusTip(tr("Show the Options box")); 339bb02e0acSNicolas Bonnefon connect( optionsAction, SIGNAL(triggered()), this, SLOT(options()) ); 340bb02e0acSNicolas Bonnefon 341bb02e0acSNicolas Bonnefon aboutAction = new QAction(tr("&About"), this); 342bb02e0acSNicolas Bonnefon aboutAction->setStatusTip(tr("Show the About box")); 343bb02e0acSNicolas Bonnefon connect( aboutAction, SIGNAL(triggered()), this, SLOT(about()) ); 344bb02e0acSNicolas Bonnefon 345bb02e0acSNicolas Bonnefon aboutQtAction = new QAction(tr("About &Qt"), this); 3465fa25391SNicolas Bonnefon aboutQtAction->setStatusTip(tr("Show the Qt library's About box")); 347bb02e0acSNicolas Bonnefon connect( aboutQtAction, SIGNAL(triggered()), this, SLOT(aboutQt()) ); 3485fa25391SNicolas Bonnefon 3495fa25391SNicolas Bonnefon encodingGroup = new QActionGroup( this ); 3505fa25391SNicolas Bonnefon 351209000a6SNicolas Bonnefon for ( int i = 0; i < static_cast<int>( Encoding::ENCODING_MAX ); ++i ) { 3525fa25391SNicolas Bonnefon encodingAction[i] = new QAction( tr( encoding_list[i].name ), this ); 3535fa25391SNicolas Bonnefon encodingAction[i]->setCheckable( true ); 3545fa25391SNicolas Bonnefon encodingGroup->addAction( encodingAction[i] ); 3555fa25391SNicolas Bonnefon } 3565fa25391SNicolas Bonnefon 3575fa25391SNicolas Bonnefon encodingAction[0]->setStatusTip(tr("Automatically detect the file's encoding")); 3585fa25391SNicolas Bonnefon encodingAction[0]->setChecked( true ); 3595fa25391SNicolas Bonnefon 3605fa25391SNicolas Bonnefon connect( encodingGroup, SIGNAL( triggered( QAction* ) ), 3615fa25391SNicolas Bonnefon this, SLOT( encodingChanged( QAction* ) ) ); 362bb02e0acSNicolas Bonnefon } 363bb02e0acSNicolas Bonnefon 364bb02e0acSNicolas Bonnefon void MainWindow::createMenus() 365bb02e0acSNicolas Bonnefon { 366bb02e0acSNicolas Bonnefon fileMenu = menuBar()->addMenu( tr("&File") ); 367bb02e0acSNicolas Bonnefon fileMenu->addAction( openAction ); 36863dc3514SGustav Andersson fileMenu->addAction( closeAction ); 36963dc3514SGustav Andersson fileMenu->addAction( closeAllAction ); 370bb02e0acSNicolas Bonnefon fileMenu->addSeparator(); 371bb02e0acSNicolas Bonnefon for (int i = 0; i < MaxRecentFiles; ++i) { 372bb02e0acSNicolas Bonnefon fileMenu->addAction( recentFileActions[i] ); 373bb02e0acSNicolas Bonnefon recentFileActionBehaviors[i] = 374bb02e0acSNicolas Bonnefon new MenuActionToolTipBehavior(recentFileActions[i], fileMenu, this); 375bb02e0acSNicolas Bonnefon } 376bb02e0acSNicolas Bonnefon fileMenu->addSeparator(); 377bb02e0acSNicolas Bonnefon fileMenu->addAction( exitAction ); 378bb02e0acSNicolas Bonnefon 379bb02e0acSNicolas Bonnefon editMenu = menuBar()->addMenu( tr("&Edit") ); 380bb02e0acSNicolas Bonnefon editMenu->addAction( copyAction ); 381bb02e0acSNicolas Bonnefon editMenu->addAction( selectAllAction ); 382bb02e0acSNicolas Bonnefon editMenu->addSeparator(); 383bb02e0acSNicolas Bonnefon editMenu->addAction( findAction ); 384bb02e0acSNicolas Bonnefon 385bb02e0acSNicolas Bonnefon viewMenu = menuBar()->addMenu( tr("&View") ); 386bb02e0acSNicolas Bonnefon viewMenu->addAction( overviewVisibleAction ); 387bb02e0acSNicolas Bonnefon viewMenu->addSeparator(); 388bb02e0acSNicolas Bonnefon viewMenu->addAction( lineNumbersVisibleInMainAction ); 389bb02e0acSNicolas Bonnefon viewMenu->addAction( lineNumbersVisibleInFilteredAction ); 390bb02e0acSNicolas Bonnefon viewMenu->addSeparator(); 391bb02e0acSNicolas Bonnefon viewMenu->addAction( followAction ); 392bb02e0acSNicolas Bonnefon viewMenu->addSeparator(); 393bb02e0acSNicolas Bonnefon viewMenu->addAction( reloadAction ); 394bb02e0acSNicolas Bonnefon 395bb02e0acSNicolas Bonnefon toolsMenu = menuBar()->addMenu( tr("&Tools") ); 396bb02e0acSNicolas Bonnefon toolsMenu->addAction( filtersAction ); 397bb02e0acSNicolas Bonnefon toolsMenu->addSeparator(); 398bb02e0acSNicolas Bonnefon toolsMenu->addAction( optionsAction ); 399bb02e0acSNicolas Bonnefon 4005fa25391SNicolas Bonnefon encodingMenu = menuBar()->addMenu( tr("En&coding") ); 4015fa25391SNicolas Bonnefon encodingMenu->addAction( encodingAction[0] ); 4025fa25391SNicolas Bonnefon encodingMenu->addSeparator(); 403209000a6SNicolas Bonnefon for ( int i = 1; i < static_cast<int>( Encoding::ENCODING_MAX ); ++i ) { 4045fa25391SNicolas Bonnefon encodingMenu->addAction( encodingAction[i] ); 4055fa25391SNicolas Bonnefon } 4065fa25391SNicolas Bonnefon 407bb02e0acSNicolas Bonnefon menuBar()->addSeparator(); 408bb02e0acSNicolas Bonnefon 409bb02e0acSNicolas Bonnefon helpMenu = menuBar()->addMenu( tr("&Help") ); 410bb02e0acSNicolas Bonnefon helpMenu->addAction( aboutAction ); 411bb02e0acSNicolas Bonnefon } 412bb02e0acSNicolas Bonnefon 413bb02e0acSNicolas Bonnefon void MainWindow::createToolBars() 414bb02e0acSNicolas Bonnefon { 415bb02e0acSNicolas Bonnefon infoLine = new InfoLine(); 416bb02e0acSNicolas Bonnefon infoLine->setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); 417bb02e0acSNicolas Bonnefon infoLine->setLineWidth( 0 ); 418bb02e0acSNicolas Bonnefon 419bb02e0acSNicolas Bonnefon lineNbField = new QLabel( ); 420bb02e0acSNicolas Bonnefon lineNbField->setText( "Line 0" ); 421bb02e0acSNicolas Bonnefon lineNbField->setAlignment( Qt::AlignLeft | Qt::AlignVCenter ); 422bb02e0acSNicolas Bonnefon lineNbField->setMinimumSize( 423bb02e0acSNicolas Bonnefon lineNbField->fontMetrics().size( 0, "Line 0000000") ); 424bb02e0acSNicolas Bonnefon 425bb02e0acSNicolas Bonnefon toolBar = addToolBar( tr("&Toolbar") ); 426c633ced3SNicolas Bonnefon toolBar->setIconSize( QSize( 14, 14 ) ); 427bb02e0acSNicolas Bonnefon toolBar->setMovable( false ); 428bb02e0acSNicolas Bonnefon toolBar->addAction( openAction ); 429bb02e0acSNicolas Bonnefon toolBar->addAction( reloadAction ); 430bb02e0acSNicolas Bonnefon toolBar->addWidget( infoLine ); 431bb02e0acSNicolas Bonnefon toolBar->addAction( stopAction ); 432bb02e0acSNicolas Bonnefon toolBar->addWidget( lineNbField ); 433bb02e0acSNicolas Bonnefon } 434bb02e0acSNicolas Bonnefon 435bb02e0acSNicolas Bonnefon // 436bb02e0acSNicolas Bonnefon // Slots 437bb02e0acSNicolas Bonnefon // 438bb02e0acSNicolas Bonnefon 439bb02e0acSNicolas Bonnefon // Opens the file selection dialog to select a new log file 440bb02e0acSNicolas Bonnefon void MainWindow::open() 441bb02e0acSNicolas Bonnefon { 442bb02e0acSNicolas Bonnefon QString defaultDir = "."; 443bb02e0acSNicolas Bonnefon 444bb02e0acSNicolas Bonnefon // Default to the path of the current file if there is one 4450e97f16dSNicolas Bonnefon if ( auto current = currentCrawlerWidget() ) 4460e97f16dSNicolas Bonnefon { 4470e97f16dSNicolas Bonnefon std::string current_file = session_->getFilename( current ); 4480e97f16dSNicolas Bonnefon QFileInfo fileInfo = QFileInfo( QString( current_file.c_str() ) ); 449bb02e0acSNicolas Bonnefon defaultDir = fileInfo.path(); 450bb02e0acSNicolas Bonnefon } 451bb02e0acSNicolas Bonnefon 452bb02e0acSNicolas Bonnefon QString fileName = QFileDialog::getOpenFileName(this, 453bb02e0acSNicolas Bonnefon tr("Open file"), defaultDir, tr("All files (*)")); 454bb02e0acSNicolas Bonnefon if (!fileName.isEmpty()) 455bb02e0acSNicolas Bonnefon loadFile(fileName); 456bb02e0acSNicolas Bonnefon } 457bb02e0acSNicolas Bonnefon 458bb02e0acSNicolas Bonnefon // Opens a log file from the recent files list 459bb02e0acSNicolas Bonnefon void MainWindow::openRecentFile() 460bb02e0acSNicolas Bonnefon { 461bb02e0acSNicolas Bonnefon QAction* action = qobject_cast<QAction*>(sender()); 462bb02e0acSNicolas Bonnefon if (action) 463bb02e0acSNicolas Bonnefon loadFile(action->data().toString()); 464bb02e0acSNicolas Bonnefon } 465bb02e0acSNicolas Bonnefon 46663dc3514SGustav Andersson // Close current tab 46763dc3514SGustav Andersson void MainWindow::closeTab() 46863dc3514SGustav Andersson { 46963dc3514SGustav Andersson int currentIndex = mainTabWidget_.currentIndex(); 47063dc3514SGustav Andersson 47163dc3514SGustav Andersson if ( currentIndex >= 0 ) 47263dc3514SGustav Andersson { 47363dc3514SGustav Andersson closeTab(currentIndex); 47463dc3514SGustav Andersson } 47563dc3514SGustav Andersson } 47663dc3514SGustav Andersson 47763dc3514SGustav Andersson // Close all tabs 47863dc3514SGustav Andersson void MainWindow::closeAll() 47963dc3514SGustav Andersson { 48063dc3514SGustav Andersson while ( mainTabWidget_.count() ) 48163dc3514SGustav Andersson { 48263dc3514SGustav Andersson closeTab(0); 48363dc3514SGustav Andersson } 48463dc3514SGustav Andersson } 48563dc3514SGustav Andersson 486bb02e0acSNicolas Bonnefon // Select all the text in the currently selected view 487bb02e0acSNicolas Bonnefon void MainWindow::selectAll() 488bb02e0acSNicolas Bonnefon { 48927ddfd3aSNicolas Bonnefon CrawlerWidget* current = currentCrawlerWidget(); 49027ddfd3aSNicolas Bonnefon 49127ddfd3aSNicolas Bonnefon if ( current ) 49227ddfd3aSNicolas Bonnefon current->selectAll(); 493bb02e0acSNicolas Bonnefon } 494bb02e0acSNicolas Bonnefon 495bb02e0acSNicolas Bonnefon // Copy the currently selected line into the clipboard 496bb02e0acSNicolas Bonnefon void MainWindow::copy() 497bb02e0acSNicolas Bonnefon { 498bb02e0acSNicolas Bonnefon static QClipboard* clipboard = QApplication::clipboard(); 49927ddfd3aSNicolas Bonnefon CrawlerWidget* current = currentCrawlerWidget(); 500bb02e0acSNicolas Bonnefon 50127ddfd3aSNicolas Bonnefon if ( current ) { 50227ddfd3aSNicolas Bonnefon clipboard->setText( current->getSelectedText() ); 503bb02e0acSNicolas Bonnefon 504bb02e0acSNicolas Bonnefon // Put it in the global selection as well (X11 only) 50527ddfd3aSNicolas Bonnefon clipboard->setText( current->getSelectedText(), 506bb02e0acSNicolas Bonnefon QClipboard::Selection ); 507bb02e0acSNicolas Bonnefon } 50827ddfd3aSNicolas Bonnefon } 509bb02e0acSNicolas Bonnefon 510bb02e0acSNicolas Bonnefon // Display the QuickFind bar 511bb02e0acSNicolas Bonnefon void MainWindow::find() 512bb02e0acSNicolas Bonnefon { 513b423cd88SNicolas Bonnefon displayQuickFindBar( QuickFindMux::Forward ); 514bb02e0acSNicolas Bonnefon } 515bb02e0acSNicolas Bonnefon 516bb02e0acSNicolas Bonnefon // Opens the 'Filters' dialog box 517bb02e0acSNicolas Bonnefon void MainWindow::filters() 518bb02e0acSNicolas Bonnefon { 519bb02e0acSNicolas Bonnefon FiltersDialog dialog(this); 52027ddfd3aSNicolas Bonnefon signalMux_.connect(&dialog, SIGNAL( optionsChanged() ), SLOT( applyConfiguration() )); 521bb02e0acSNicolas Bonnefon dialog.exec(); 52227ddfd3aSNicolas Bonnefon signalMux_.disconnect(&dialog, SIGNAL( optionsChanged() ), SLOT( applyConfiguration() )); 523bb02e0acSNicolas Bonnefon } 524bb02e0acSNicolas Bonnefon 525bb02e0acSNicolas Bonnefon // Opens the 'Options' modal dialog box 526bb02e0acSNicolas Bonnefon void MainWindow::options() 527bb02e0acSNicolas Bonnefon { 528bb02e0acSNicolas Bonnefon OptionsDialog dialog(this); 52927ddfd3aSNicolas Bonnefon signalMux_.connect(&dialog, SIGNAL( optionsChanged() ), SLOT( applyConfiguration() )); 530bb02e0acSNicolas Bonnefon dialog.exec(); 53127ddfd3aSNicolas Bonnefon signalMux_.disconnect(&dialog, SIGNAL( optionsChanged() ), SLOT( applyConfiguration() )); 532bb02e0acSNicolas Bonnefon } 533bb02e0acSNicolas Bonnefon 534bb02e0acSNicolas Bonnefon // Opens the 'About' dialog box. 535bb02e0acSNicolas Bonnefon void MainWindow::about() 536bb02e0acSNicolas Bonnefon { 537bb02e0acSNicolas Bonnefon QMessageBox::about(this, tr("About glogg"), 538bb02e0acSNicolas Bonnefon tr("<h2>glogg " GLOGG_VERSION "</h2>" 539bb02e0acSNicolas Bonnefon "<p>A fast, advanced log explorer." 540bb02e0acSNicolas Bonnefon #ifdef GLOGG_COMMIT 541bb02e0acSNicolas Bonnefon "<p>Built " GLOGG_DATE " from " GLOGG_COMMIT 542bb02e0acSNicolas Bonnefon #endif 54335c20658SNicolas Bonnefon "<p><a href=\"http://glogg.bonnefon.org/\">http://glogg.bonnefon.org/</a></p>" 5445fa25391SNicolas Bonnefon "<p>Copyright © 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Nicolas Bonnefon and other contributors" 545bb02e0acSNicolas Bonnefon "<p>You may modify and redistribute the program under the terms of the GPL (version 3 or later)." ) ); 546bb02e0acSNicolas Bonnefon } 547bb02e0acSNicolas Bonnefon 548bb02e0acSNicolas Bonnefon // Opens the 'About Qt' dialog box. 549bb02e0acSNicolas Bonnefon void MainWindow::aboutQt() 550bb02e0acSNicolas Bonnefon { 551bb02e0acSNicolas Bonnefon } 552bb02e0acSNicolas Bonnefon 5535fa25391SNicolas Bonnefon void MainWindow::encodingChanged( QAction* action ) 5545fa25391SNicolas Bonnefon { 5555fa25391SNicolas Bonnefon int i = 0; 556209000a6SNicolas Bonnefon for ( i = 0; i < static_cast<int>( Encoding::ENCODING_MAX ); ++i ) 5575fa25391SNicolas Bonnefon if ( action == encodingAction[i] ) 5585fa25391SNicolas Bonnefon break; 5595fa25391SNicolas Bonnefon 5605fa25391SNicolas Bonnefon LOG(logDEBUG) << "encodingChanged, encoding " << i; 561209000a6SNicolas Bonnefon currentCrawlerWidget()->setEncoding( static_cast<Encoding>( i ) ); 5625fa25391SNicolas Bonnefon updateInfoLine(); 5635fa25391SNicolas Bonnefon } 5645fa25391SNicolas Bonnefon 565bb02e0acSNicolas Bonnefon void MainWindow::toggleOverviewVisibility( bool isVisible ) 566bb02e0acSNicolas Bonnefon { 56711582726SNicolas Bonnefon std::shared_ptr<Configuration> config = 56811582726SNicolas Bonnefon Persistent<Configuration>( "settings" ); 56911582726SNicolas Bonnefon config->setOverviewVisible( isVisible ); 570bb02e0acSNicolas Bonnefon emit optionsChanged(); 571bb02e0acSNicolas Bonnefon } 572bb02e0acSNicolas Bonnefon 573bb02e0acSNicolas Bonnefon void MainWindow::toggleMainLineNumbersVisibility( bool isVisible ) 574bb02e0acSNicolas Bonnefon { 57511582726SNicolas Bonnefon std::shared_ptr<Configuration> config = 57611582726SNicolas Bonnefon Persistent<Configuration>( "settings" ); 57711582726SNicolas Bonnefon config->setMainLineNumbersVisible( isVisible ); 578bb02e0acSNicolas Bonnefon emit optionsChanged(); 579bb02e0acSNicolas Bonnefon } 580bb02e0acSNicolas Bonnefon 581bb02e0acSNicolas Bonnefon void MainWindow::toggleFilteredLineNumbersVisibility( bool isVisible ) 582bb02e0acSNicolas Bonnefon { 58311582726SNicolas Bonnefon std::shared_ptr<Configuration> config = 58411582726SNicolas Bonnefon Persistent<Configuration>( "settings" ); 58511582726SNicolas Bonnefon config->setFilteredLineNumbersVisible( isVisible ); 586bb02e0acSNicolas Bonnefon emit optionsChanged(); 587bb02e0acSNicolas Bonnefon } 588bb02e0acSNicolas Bonnefon 589b297d2f4SNicolas Bonnefon void MainWindow::changeFollowMode( bool follow ) 590bb02e0acSNicolas Bonnefon { 591b297d2f4SNicolas Bonnefon followAction->setChecked( follow ); 592bb02e0acSNicolas Bonnefon } 593bb02e0acSNicolas Bonnefon 594bb02e0acSNicolas Bonnefon void MainWindow::lineNumberHandler( int line ) 595bb02e0acSNicolas Bonnefon { 596bb02e0acSNicolas Bonnefon // The line number received is the internal (starts at 0) 597bb02e0acSNicolas Bonnefon lineNbField->setText( tr( "Line %1" ).arg( line + 1 ) ); 598bb02e0acSNicolas Bonnefon } 599bb02e0acSNicolas Bonnefon 600bb02e0acSNicolas Bonnefon void MainWindow::updateLoadingProgress( int progress ) 601bb02e0acSNicolas Bonnefon { 602bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "Loading progress: " << progress; 603bb02e0acSNicolas Bonnefon 604f8bd90d8SNicolas Bonnefon QString current_file = 605f8bd90d8SNicolas Bonnefon session_->getFilename( currentCrawlerWidget() ).c_str(); 6060e97f16dSNicolas Bonnefon 607bb02e0acSNicolas Bonnefon // We ignore 0% and 100% to avoid a flash when the file (or update) 608bb02e0acSNicolas Bonnefon // is very short. 609bb02e0acSNicolas Bonnefon if ( progress > 0 && progress < 100 ) { 610f8bd90d8SNicolas Bonnefon infoLine->setText( current_file + 611f8bd90d8SNicolas Bonnefon tr( " - Indexing lines... (%1 %)" ).arg( progress ) ); 612bb02e0acSNicolas Bonnefon infoLine->displayGauge( progress ); 613bb02e0acSNicolas Bonnefon 614bb02e0acSNicolas Bonnefon stopAction->setEnabled( true ); 615f8bd90d8SNicolas Bonnefon reloadAction->setEnabled( false ); 616bb02e0acSNicolas Bonnefon } 617bb02e0acSNicolas Bonnefon } 618bb02e0acSNicolas Bonnefon 619812146a8SNicolas Bonnefon void MainWindow::handleLoadingFinished( LoadingStatus status ) 620bb02e0acSNicolas Bonnefon { 621812146a8SNicolas Bonnefon LOG(logDEBUG) << "handleLoadingFinished success=" << 622812146a8SNicolas Bonnefon ( status == LoadingStatus::Successful ); 623bb02e0acSNicolas Bonnefon 6240e97f16dSNicolas Bonnefon // No file is loading 6250e97f16dSNicolas Bonnefon loadingFileName.clear(); 6260e97f16dSNicolas Bonnefon 627812146a8SNicolas Bonnefon if ( status == LoadingStatus::Successful ) 628f8bd90d8SNicolas Bonnefon { 6295fa25391SNicolas Bonnefon updateInfoLine(); 630bb02e0acSNicolas Bonnefon 631bb02e0acSNicolas Bonnefon infoLine->hideGauge(); 632bb02e0acSNicolas Bonnefon stopAction->setEnabled( false ); 633f8bd90d8SNicolas Bonnefon reloadAction->setEnabled( true ); 6340a90ca6aSNicolas Bonnefon 6350a90ca6aSNicolas Bonnefon // Now everything is ready, we can finally show the file! 63627ddfd3aSNicolas Bonnefon currentCrawlerWidget()->show(); 637f8bd90d8SNicolas Bonnefon } 638f8bd90d8SNicolas Bonnefon else 639f8bd90d8SNicolas Bonnefon { 640812146a8SNicolas Bonnefon if ( status == LoadingStatus::NoMemory ) 641812146a8SNicolas Bonnefon { 642812146a8SNicolas Bonnefon QMessageBox alertBox; 643812146a8SNicolas Bonnefon alertBox.setText( "Not enough memory." ); 644812146a8SNicolas Bonnefon alertBox.setInformativeText( "The system does not have enough \ 645812146a8SNicolas Bonnefon memory to hold the index for this file. The file will now be closed." ); 646812146a8SNicolas Bonnefon alertBox.setIcon( QMessageBox::Critical ); 647812146a8SNicolas Bonnefon alertBox.exec(); 648812146a8SNicolas Bonnefon } 649812146a8SNicolas Bonnefon 650f8bd90d8SNicolas Bonnefon closeTab( mainTabWidget_.currentIndex() ); 651f8bd90d8SNicolas Bonnefon } 652f8bd90d8SNicolas Bonnefon 6537875bde2SNicolas Bonnefon // mainTabWidget_.setEnabled( true ); 654bb02e0acSNicolas Bonnefon } 655bb02e0acSNicolas Bonnefon 656f688be2eSNicolas Bonnefon void MainWindow::handleSearchRefreshChanged( int state ) 657f688be2eSNicolas Bonnefon { 658f688be2eSNicolas Bonnefon auto config = Persistent<Configuration>( "settings" ); 659f688be2eSNicolas Bonnefon config->setSearchAutoRefreshDefault( state == Qt::Checked ); 660f688be2eSNicolas Bonnefon } 661f688be2eSNicolas Bonnefon 662f688be2eSNicolas Bonnefon void MainWindow::handleIgnoreCaseChanged( int state ) 663f688be2eSNicolas Bonnefon { 664f688be2eSNicolas Bonnefon auto config = Persistent<Configuration>( "settings" ); 665f688be2eSNicolas Bonnefon config->setSearchIgnoreCaseDefault( state == Qt::Checked ); 666f688be2eSNicolas Bonnefon } 667f688be2eSNicolas Bonnefon 668cdd89779SNicolas Bonnefon void MainWindow::closeTab( int index ) 669cdd89779SNicolas Bonnefon { 670cdd89779SNicolas Bonnefon auto widget = dynamic_cast<CrawlerWidget*>( 671cdd89779SNicolas Bonnefon mainTabWidget_.widget( index ) ); 672cdd89779SNicolas Bonnefon 673cdd89779SNicolas Bonnefon assert( widget ); 674cdd89779SNicolas Bonnefon 675f8bd90d8SNicolas Bonnefon widget->stopLoading(); 676cdd89779SNicolas Bonnefon mainTabWidget_.removeTab( index ); 677cdd89779SNicolas Bonnefon session_->close( widget ); 678cdd89779SNicolas Bonnefon delete widget; 679cdd89779SNicolas Bonnefon } 680cdd89779SNicolas Bonnefon 681ee835f33SNicolas Bonnefon void MainWindow::currentTabChanged( int index ) 682ee835f33SNicolas Bonnefon { 683ee835f33SNicolas Bonnefon LOG(logDEBUG) << "currentTabChanged"; 684ee835f33SNicolas Bonnefon 685ee835f33SNicolas Bonnefon if ( index >= 0 ) 686ee835f33SNicolas Bonnefon { 687ee835f33SNicolas Bonnefon CrawlerWidget* crawler_widget = dynamic_cast<CrawlerWidget*>( 688ee835f33SNicolas Bonnefon mainTabWidget_.widget( index ) ); 689ee835f33SNicolas Bonnefon signalMux_.setCurrentDocument( crawler_widget ); 690ee835f33SNicolas Bonnefon quickFindMux_.registerSelector( crawler_widget ); 691ee835f33SNicolas Bonnefon 692ee835f33SNicolas Bonnefon // New tab is set up with fonts etc... 693ee835f33SNicolas Bonnefon emit optionsChanged(); 6940e97f16dSNicolas Bonnefon 6955fa25391SNicolas Bonnefon // Update the menu bar 6965fa25391SNicolas Bonnefon updateMenuBarFromDocument( crawler_widget ); 6975fa25391SNicolas Bonnefon 6980e97f16dSNicolas Bonnefon // Update the title bar 6990e97f16dSNicolas Bonnefon updateTitleBar( QString( 7000e97f16dSNicolas Bonnefon session_->getFilename( crawler_widget ).c_str() ) ); 701ee835f33SNicolas Bonnefon } 702ee835f33SNicolas Bonnefon else 703ee835f33SNicolas Bonnefon { 704a1202e0cSNicolas Bonnefon // No tab left 705a1202e0cSNicolas Bonnefon signalMux_.setCurrentDocument( nullptr ); 706a1202e0cSNicolas Bonnefon quickFindMux_.registerSelector( nullptr ); 707a1202e0cSNicolas Bonnefon 708a1202e0cSNicolas Bonnefon infoLine->hideGauge(); 709a1202e0cSNicolas Bonnefon infoLine->clear(); 710a1202e0cSNicolas Bonnefon 711a1202e0cSNicolas Bonnefon updateTitleBar( QString() ); 712ee835f33SNicolas Bonnefon } 713ee835f33SNicolas Bonnefon } 714ee835f33SNicolas Bonnefon 7158570d8d2SNicolas Bonnefon void MainWindow::changeQFPattern( const QString& newPattern ) 7168570d8d2SNicolas Bonnefon { 7178570d8d2SNicolas Bonnefon quickFindWidget_.changeDisplayedPattern( newPattern ); 7188570d8d2SNicolas Bonnefon } 7198570d8d2SNicolas Bonnefon 72009aff35dSNicolas Bonnefon void MainWindow::loadFileNonInteractive( const QString& file_name ) 72109aff35dSNicolas Bonnefon { 72209aff35dSNicolas Bonnefon LOG(logDEBUG) << "loadFileNonInteractive( " 72309aff35dSNicolas Bonnefon << file_name.toStdString() << " )"; 72409aff35dSNicolas Bonnefon 72509aff35dSNicolas Bonnefon loadFile( file_name ); 72667cec333SNicolas Bonnefon 72767cec333SNicolas Bonnefon // Try to get the window to the front 72867cec333SNicolas Bonnefon // This is a bit of a hack but has been tested on: 72967cec333SNicolas Bonnefon // Qt 5.3 / Gnome / Linux 730cf609627SNicolas Bonnefon // Qt 4.8 / Win7 731cf609627SNicolas Bonnefon #ifdef _WIN32 732cf609627SNicolas Bonnefon // Hack copied from http://qt-project.org/forums/viewthread/6164 7338f46a826SNicolas Bonnefon ::SetWindowPos((HWND) effectiveWinId(), HWND_TOPMOST, 734cf609627SNicolas Bonnefon 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); 7358f46a826SNicolas Bonnefon ::SetWindowPos((HWND) effectiveWinId(), HWND_NOTOPMOST, 736cf609627SNicolas Bonnefon 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); 737cf609627SNicolas Bonnefon #else 73867cec333SNicolas Bonnefon Qt::WindowFlags window_flags = windowFlags(); 73967cec333SNicolas Bonnefon window_flags |= Qt::WindowStaysOnTopHint; 74067cec333SNicolas Bonnefon setWindowFlags( window_flags ); 741cf609627SNicolas Bonnefon #endif 74267cec333SNicolas Bonnefon 74367cec333SNicolas Bonnefon activateWindow(); 74467cec333SNicolas Bonnefon raise(); 74567cec333SNicolas Bonnefon 746cf609627SNicolas Bonnefon #ifndef _WIN32 74767cec333SNicolas Bonnefon window_flags = windowFlags(); 74867cec333SNicolas Bonnefon window_flags &= ~Qt::WindowStaysOnTopHint; 74967cec333SNicolas Bonnefon setWindowFlags( window_flags ); 750cf609627SNicolas Bonnefon #endif 75167cec333SNicolas Bonnefon 752cf609627SNicolas Bonnefon showNormal(); 75309aff35dSNicolas Bonnefon } 75409aff35dSNicolas Bonnefon 755460de700SNicolas Bonnefon void MainWindow::newVersionNotification( const QString& new_version ) 756460de700SNicolas Bonnefon { 757460de700SNicolas Bonnefon LOG(logDEBUG) << "newVersionNotification( " << 758460de700SNicolas Bonnefon new_version.toStdString() << " )"; 759460de700SNicolas Bonnefon 760460de700SNicolas Bonnefon QMessageBox msgBox; 761460de700SNicolas Bonnefon msgBox.setText( QString( "A new version of glogg (%1) is available for download <p>" 762460de700SNicolas Bonnefon "<a href=\"http://glogg.bonnefon.org/download.html\">http://glogg.bonnefon.org/download.html</a>" 763460de700SNicolas Bonnefon ).arg( new_version ) ); 764460de700SNicolas Bonnefon msgBox.exec(); 765460de700SNicolas Bonnefon } 766460de700SNicolas Bonnefon 767bb02e0acSNicolas Bonnefon // 768bb02e0acSNicolas Bonnefon // Events 769bb02e0acSNicolas Bonnefon // 770bb02e0acSNicolas Bonnefon 771bb02e0acSNicolas Bonnefon // Closes the application 772bb02e0acSNicolas Bonnefon void MainWindow::closeEvent( QCloseEvent *event ) 773bb02e0acSNicolas Bonnefon { 774bb02e0acSNicolas Bonnefon writeSettings(); 775bb02e0acSNicolas Bonnefon event->accept(); 776bb02e0acSNicolas Bonnefon } 777bb02e0acSNicolas Bonnefon 778bb02e0acSNicolas Bonnefon // Accepts the drag event if it looks like a filename 779bb02e0acSNicolas Bonnefon void MainWindow::dragEnterEvent( QDragEnterEvent* event ) 780bb02e0acSNicolas Bonnefon { 781bb02e0acSNicolas Bonnefon if ( event->mimeData()->hasFormat( "text/uri-list" ) ) 782bb02e0acSNicolas Bonnefon event->acceptProposedAction(); 783bb02e0acSNicolas Bonnefon } 784bb02e0acSNicolas Bonnefon 785bb02e0acSNicolas Bonnefon // Tries and loads the file if the URL dropped is local 786bb02e0acSNicolas Bonnefon void MainWindow::dropEvent( QDropEvent* event ) 787bb02e0acSNicolas Bonnefon { 788fa36e4ddSAnton Filimonov foreach( const QUrl& url, event->mimeData()->urls() ) { 789fa36e4ddSAnton Filimonov QString fileName = url.toLocalFile(); 790fa36e4ddSAnton Filimonov if ( !fileName.isEmpty() ) { 791bb02e0acSNicolas Bonnefon loadFile( fileName ); 792bb02e0acSNicolas Bonnefon } 793fa36e4ddSAnton Filimonov } 794fa36e4ddSAnton Filimonov } 795bb02e0acSNicolas Bonnefon 7968570d8d2SNicolas Bonnefon void MainWindow::keyPressEvent( QKeyEvent* keyEvent ) 7978570d8d2SNicolas Bonnefon { 7988570d8d2SNicolas Bonnefon LOG(logDEBUG4) << "keyPressEvent received"; 7998570d8d2SNicolas Bonnefon 8008570d8d2SNicolas Bonnefon switch ( (keyEvent->text())[0].toLatin1() ) { 8018570d8d2SNicolas Bonnefon case '/': 8028570d8d2SNicolas Bonnefon displayQuickFindBar( QuickFindMux::Forward ); 8038570d8d2SNicolas Bonnefon break; 8048570d8d2SNicolas Bonnefon case '?': 8058570d8d2SNicolas Bonnefon displayQuickFindBar( QuickFindMux::Backward ); 8068570d8d2SNicolas Bonnefon break; 8078570d8d2SNicolas Bonnefon default: 8088570d8d2SNicolas Bonnefon keyEvent->ignore(); 8098570d8d2SNicolas Bonnefon } 8108570d8d2SNicolas Bonnefon 8118570d8d2SNicolas Bonnefon if ( !keyEvent->isAccepted() ) 8128570d8d2SNicolas Bonnefon QMainWindow::keyPressEvent( keyEvent ); 8138570d8d2SNicolas Bonnefon } 8148570d8d2SNicolas Bonnefon 815bb02e0acSNicolas Bonnefon // 816bb02e0acSNicolas Bonnefon // Private functions 817bb02e0acSNicolas Bonnefon // 818bb02e0acSNicolas Bonnefon 8190a90ca6aSNicolas Bonnefon // Create a CrawlerWidget for the passed file, start its loading 8200a90ca6aSNicolas Bonnefon // and update the title bar. 821bb02e0acSNicolas Bonnefon // The loading is done asynchronously. 822bb02e0acSNicolas Bonnefon bool MainWindow::loadFile( const QString& fileName ) 823bb02e0acSNicolas Bonnefon { 824bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "loadFile ( " << fileName.toStdString() << " )"; 825bb02e0acSNicolas Bonnefon 8263b4aad7fSNicolas Bonnefon // First check if the file is already open... 8273b4aad7fSNicolas Bonnefon CrawlerWidget* existing_crawler = dynamic_cast<CrawlerWidget*>( 8283b4aad7fSNicolas Bonnefon session_->getViewIfOpen( fileName.toStdString() ) ); 8293b4aad7fSNicolas Bonnefon if ( existing_crawler ) { 8303b4aad7fSNicolas Bonnefon // ... and switch to it. 8313b4aad7fSNicolas Bonnefon mainTabWidget_.setCurrentWidget( existing_crawler ); 8323b4aad7fSNicolas Bonnefon 8333b4aad7fSNicolas Bonnefon return true; 8343b4aad7fSNicolas Bonnefon } 8353b4aad7fSNicolas Bonnefon 836bb02e0acSNicolas Bonnefon // Load the file 837bb02e0acSNicolas Bonnefon loadingFileName = fileName; 838039481acSNicolas Bonnefon 839a3b56311SNicolas Bonnefon try { 84027ddfd3aSNicolas Bonnefon CrawlerWidget* crawler_widget = dynamic_cast<CrawlerWidget*>( 84127ddfd3aSNicolas Bonnefon session_->open( fileName.toStdString(), 8421b5e406eSNicolas Bonnefon []() { return new CrawlerWidget(); } ) ); 8431b5e406eSNicolas Bonnefon assert( crawler_widget ); 844f0708ca8SNicolas Bonnefon 8450a90ca6aSNicolas Bonnefon // We won't show the widget until the file is fully loaded 84627ddfd3aSNicolas Bonnefon crawler_widget->hide(); 847f0708ca8SNicolas Bonnefon 84827ddfd3aSNicolas Bonnefon // We disable the tab widget to avoid having someone switch 84927ddfd3aSNicolas Bonnefon // tab during loading. (maybe FIXME) 8507875bde2SNicolas Bonnefon //mainTabWidget_.setEnabled( false ); 851313a820fSNicolas Bonnefon 852a3b56311SNicolas Bonnefon int index = mainTabWidget_.addTab( 853a3b56311SNicolas Bonnefon crawler_widget, strippedName( fileName ) ); 854f0708ca8SNicolas Bonnefon 85527ddfd3aSNicolas Bonnefon // Setting the new tab, the user will see a blank page for the duration 85627ddfd3aSNicolas Bonnefon // of the loading, with no way to switch to another tab 85727ddfd3aSNicolas Bonnefon mainTabWidget_.setCurrentIndex( index ); 85827ddfd3aSNicolas Bonnefon 85960864ff5SNicolas Bonnefon // Update the recent files list 86060864ff5SNicolas Bonnefon // (reload the list first in case another glogg changed it) 86160864ff5SNicolas Bonnefon GetPersistentInfo().retrieve( "recentFiles" ); 86211582726SNicolas Bonnefon recentFiles_->addRecent( fileName ); 86360864ff5SNicolas Bonnefon GetPersistentInfo().save( "recentFiles" ); 86460864ff5SNicolas Bonnefon updateRecentFileActions(); 865a3b56311SNicolas Bonnefon } 866a3b56311SNicolas Bonnefon catch ( FileUnreadableErr ) { 867a3b56311SNicolas Bonnefon LOG(logDEBUG) << "Can't open file " << fileName.toStdString(); 868a3b56311SNicolas Bonnefon return false; 869a3b56311SNicolas Bonnefon } 87060864ff5SNicolas Bonnefon 871bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "Success loading file " << fileName.toStdString(); 872bb02e0acSNicolas Bonnefon return true; 873a3b56311SNicolas Bonnefon 874bb02e0acSNicolas Bonnefon } 875bb02e0acSNicolas Bonnefon 876bb02e0acSNicolas Bonnefon // Strips the passed filename from its directory part. 877bb02e0acSNicolas Bonnefon QString MainWindow::strippedName( const QString& fullFileName ) const 878bb02e0acSNicolas Bonnefon { 879bb02e0acSNicolas Bonnefon return QFileInfo( fullFileName ).fileName(); 880bb02e0acSNicolas Bonnefon } 881bb02e0acSNicolas Bonnefon 88227ddfd3aSNicolas Bonnefon // Return the currently active CrawlerWidget, or NULL if none 88327ddfd3aSNicolas Bonnefon CrawlerWidget* MainWindow::currentCrawlerWidget() const 88427ddfd3aSNicolas Bonnefon { 88527ddfd3aSNicolas Bonnefon auto current = dynamic_cast<CrawlerWidget*>( 88627ddfd3aSNicolas Bonnefon mainTabWidget_.currentWidget() ); 88727ddfd3aSNicolas Bonnefon 88827ddfd3aSNicolas Bonnefon return current; 88927ddfd3aSNicolas Bonnefon } 89027ddfd3aSNicolas Bonnefon 8910e97f16dSNicolas Bonnefon // Update the title bar. 8920e97f16dSNicolas Bonnefon void MainWindow::updateTitleBar( const QString& file_name ) 893bb02e0acSNicolas Bonnefon { 894bb02e0acSNicolas Bonnefon QString shownName = tr( "Untitled" ); 8950e97f16dSNicolas Bonnefon if ( !file_name.isEmpty() ) 8960e97f16dSNicolas Bonnefon shownName = strippedName( file_name ); 897bb02e0acSNicolas Bonnefon 898bb02e0acSNicolas Bonnefon setWindowTitle( 899bb02e0acSNicolas Bonnefon tr("%1 - %2").arg(shownName).arg(tr("glogg")) 900bb02e0acSNicolas Bonnefon #ifdef GLOGG_COMMIT 901bb02e0acSNicolas Bonnefon + " (dev build " GLOGG_VERSION ")" 902bb02e0acSNicolas Bonnefon #endif 903bb02e0acSNicolas Bonnefon ); 904bb02e0acSNicolas Bonnefon } 905bb02e0acSNicolas Bonnefon 906bb02e0acSNicolas Bonnefon // Updates the actions for the recent files. 907bb02e0acSNicolas Bonnefon // Must be called after having added a new name to the list. 908bb02e0acSNicolas Bonnefon void MainWindow::updateRecentFileActions() 909bb02e0acSNicolas Bonnefon { 91011582726SNicolas Bonnefon QStringList recent_files = recentFiles_->recentFiles(); 911bb02e0acSNicolas Bonnefon 912bb02e0acSNicolas Bonnefon for ( int j = 0; j < MaxRecentFiles; ++j ) { 913bb02e0acSNicolas Bonnefon if ( j < recent_files.count() ) { 914bb02e0acSNicolas Bonnefon QString text = tr("&%1 %2").arg(j + 1).arg(strippedName(recent_files[j])); 915bb02e0acSNicolas Bonnefon recentFileActions[j]->setText( text ); 916bb02e0acSNicolas Bonnefon recentFileActions[j]->setToolTip( recent_files[j] ); 917bb02e0acSNicolas Bonnefon recentFileActions[j]->setData( recent_files[j] ); 918bb02e0acSNicolas Bonnefon recentFileActions[j]->setVisible( true ); 919bb02e0acSNicolas Bonnefon } 920bb02e0acSNicolas Bonnefon else { 921bb02e0acSNicolas Bonnefon recentFileActions[j]->setVisible( false ); 922bb02e0acSNicolas Bonnefon } 923bb02e0acSNicolas Bonnefon } 924bb02e0acSNicolas Bonnefon 925bb02e0acSNicolas Bonnefon // separatorAction->setVisible(!recentFiles.isEmpty()); 926bb02e0acSNicolas Bonnefon } 927bb02e0acSNicolas Bonnefon 9285fa25391SNicolas Bonnefon // Update our menu bar to match the settings of the crawler 9295fa25391SNicolas Bonnefon // (used when the tab is changed) 9305fa25391SNicolas Bonnefon void MainWindow::updateMenuBarFromDocument( const CrawlerWidget* crawler ) 9315fa25391SNicolas Bonnefon { 9325fa25391SNicolas Bonnefon auto encoding = crawler->encodingSetting(); 9335fa25391SNicolas Bonnefon encodingAction[static_cast<int>( encoding )]->setChecked( true ); 93478dc0425SNicolas Bonnefon bool follow = crawler->isFollowEnabled(); 93578dc0425SNicolas Bonnefon followAction->setChecked( follow ); 9365fa25391SNicolas Bonnefon } 9375fa25391SNicolas Bonnefon 9385fa25391SNicolas Bonnefon // Update the top info line from the session 9395fa25391SNicolas Bonnefon void MainWindow::updateInfoLine() 9405fa25391SNicolas Bonnefon { 9415fa25391SNicolas Bonnefon QLocale defaultLocale; 9425fa25391SNicolas Bonnefon 9435fa25391SNicolas Bonnefon // Following should always work as we will only receive enter 9445fa25391SNicolas Bonnefon // this slot if there is a crawler connected. 9455fa25391SNicolas Bonnefon QString current_file = 9465fa25391SNicolas Bonnefon session_->getFilename( currentCrawlerWidget() ).c_str(); 9475fa25391SNicolas Bonnefon 9485fa25391SNicolas Bonnefon uint64_t fileSize; 9495fa25391SNicolas Bonnefon uint32_t fileNbLine; 9505fa25391SNicolas Bonnefon QDateTime lastModified; 9515fa25391SNicolas Bonnefon 9525fa25391SNicolas Bonnefon session_->getFileInfo( currentCrawlerWidget(), 9535fa25391SNicolas Bonnefon &fileSize, &fileNbLine, &lastModified ); 9545fa25391SNicolas Bonnefon if ( lastModified.isValid() ) { 9555fa25391SNicolas Bonnefon const QString date = 9565fa25391SNicolas Bonnefon defaultLocale.toString( lastModified, QLocale::NarrowFormat ); 9575fa25391SNicolas Bonnefon infoLine->setText( tr( "%1 (%2 - %3 lines - modified on %4 - %5)" ) 9585fa25391SNicolas Bonnefon .arg(current_file).arg(readableSize(fileSize)) 9595fa25391SNicolas Bonnefon .arg(fileNbLine).arg( date ) 9605fa25391SNicolas Bonnefon .arg(currentCrawlerWidget()->encodingText()) ); 9615fa25391SNicolas Bonnefon } 9625fa25391SNicolas Bonnefon else { 9635fa25391SNicolas Bonnefon infoLine->setText( tr( "%1 (%2 - %3 lines - %4)" ) 9645fa25391SNicolas Bonnefon .arg(current_file).arg(readableSize(fileSize)) 9655fa25391SNicolas Bonnefon .arg(fileNbLine) 9665fa25391SNicolas Bonnefon .arg(currentCrawlerWidget()->encodingText()) ); 9675fa25391SNicolas Bonnefon } 9685fa25391SNicolas Bonnefon } 9695fa25391SNicolas Bonnefon 970bb02e0acSNicolas Bonnefon // Write settings to permanent storage 971bb02e0acSNicolas Bonnefon void MainWindow::writeSettings() 972bb02e0acSNicolas Bonnefon { 973bb02e0acSNicolas Bonnefon // Save the session 974b57881faSNicolas Bonnefon // Generate the ordered list of widgets and their topLine 975a44d09bcSNicolas Bonnefon std::vector< 976a44d09bcSNicolas Bonnefon std::tuple<const ViewInterface*, uint64_t, std::shared_ptr<const ViewContextInterface>> 977a44d09bcSNicolas Bonnefon > widget_list; 978b57881faSNicolas Bonnefon for ( int i = 0; i < mainTabWidget_.count(); ++i ) 979a44d09bcSNicolas Bonnefon { 980a44d09bcSNicolas Bonnefon auto view = dynamic_cast<const ViewInterface*>( mainTabWidget_.widget( i ) ); 981a44d09bcSNicolas Bonnefon widget_list.push_back( std::make_tuple( 982a44d09bcSNicolas Bonnefon view, 983a44d09bcSNicolas Bonnefon 0UL, 984a44d09bcSNicolas Bonnefon view->context() ) ); 985a44d09bcSNicolas Bonnefon } 986b76966a6SNicolas Bonnefon session_->save( widget_list, saveGeometry() ); 987bb02e0acSNicolas Bonnefon 988bb02e0acSNicolas Bonnefon // User settings 989bb02e0acSNicolas Bonnefon GetPersistentInfo().save( QString( "settings" ) ); 990bb02e0acSNicolas Bonnefon } 991bb02e0acSNicolas Bonnefon 992bb02e0acSNicolas Bonnefon // Read settings from permanent storage 993bb02e0acSNicolas Bonnefon void MainWindow::readSettings() 994bb02e0acSNicolas Bonnefon { 995bb02e0acSNicolas Bonnefon // Get and restore the session 996b57881faSNicolas Bonnefon // GetPersistentInfo().retrieve( QString( "session" ) ); 997b57881faSNicolas Bonnefon // SessionInfo session = Persistent<SessionInfo>( "session" ); 9980a90ca6aSNicolas Bonnefon /* 9990a90ca6aSNicolas Bonnefon * FIXME: should be in the session 10000a90ca6aSNicolas Bonnefon crawlerWidget->restoreState( session.crawlerState() ); 10010a90ca6aSNicolas Bonnefon */ 1002bb02e0acSNicolas Bonnefon 1003bb02e0acSNicolas Bonnefon // History of recent files 1004bb02e0acSNicolas Bonnefon GetPersistentInfo().retrieve( QString( "recentFiles" ) ); 1005bb02e0acSNicolas Bonnefon updateRecentFileActions(); 1006bb02e0acSNicolas Bonnefon 1007b57881faSNicolas Bonnefon // GetPersistentInfo().retrieve( QString( "settings" ) ); 1008bb02e0acSNicolas Bonnefon GetPersistentInfo().retrieve( QString( "filterSet" ) ); 1009bb02e0acSNicolas Bonnefon } 1010bb02e0acSNicolas Bonnefon 1011b423cd88SNicolas Bonnefon void MainWindow::displayQuickFindBar( QuickFindMux::QFDirection direction ) 1012b423cd88SNicolas Bonnefon { 1013b423cd88SNicolas Bonnefon LOG(logDEBUG) << "MainWindow::displayQuickFindBar"; 1014b423cd88SNicolas Bonnefon 10158570d8d2SNicolas Bonnefon // Warn crawlers so they can save the position of the focus in order 10168570d8d2SNicolas Bonnefon // to do incremental search in the right view. 10178570d8d2SNicolas Bonnefon emit enteringQuickFind(); 1018b423cd88SNicolas Bonnefon 1019b423cd88SNicolas Bonnefon quickFindMux_.setDirection( direction ); 1020b423cd88SNicolas Bonnefon quickFindWidget_.userActivate(); 1021b423cd88SNicolas Bonnefon } 1022b423cd88SNicolas Bonnefon 1023bb02e0acSNicolas Bonnefon // Returns the size in human readable format 10240a90ca6aSNicolas Bonnefon static QString readableSize( qint64 size ) 1025bb02e0acSNicolas Bonnefon { 1026bb02e0acSNicolas Bonnefon static const QString sizeStrs[] = { 10270a90ca6aSNicolas Bonnefon QObject::tr("B"), QObject::tr("KiB"), QObject::tr("MiB"), 10280a90ca6aSNicolas Bonnefon QObject::tr("GiB"), QObject::tr("TiB") }; 1029bb02e0acSNicolas Bonnefon 1030bb02e0acSNicolas Bonnefon QLocale defaultLocale; 1031bb02e0acSNicolas Bonnefon unsigned int i; 1032bb02e0acSNicolas Bonnefon double humanSize = size; 1033bb02e0acSNicolas Bonnefon 1034bb02e0acSNicolas Bonnefon for ( i=0; i+1 < (sizeof(sizeStrs)/sizeof(QString)) && (humanSize/1024.0) >= 1024.0; i++ ) 1035bb02e0acSNicolas Bonnefon humanSize /= 1024.0; 1036bb02e0acSNicolas Bonnefon 1037bb02e0acSNicolas Bonnefon if ( humanSize >= 1024.0 ) { 1038bb02e0acSNicolas Bonnefon humanSize /= 1024.0; 1039bb02e0acSNicolas Bonnefon i++; 1040bb02e0acSNicolas Bonnefon } 1041bb02e0acSNicolas Bonnefon 1042bb02e0acSNicolas Bonnefon QString output; 1043bb02e0acSNicolas Bonnefon if ( i == 0 ) 1044bb02e0acSNicolas Bonnefon // No decimal part if we display straight bytes. 1045bb02e0acSNicolas Bonnefon output = defaultLocale.toString( (int) humanSize ); 1046bb02e0acSNicolas Bonnefon else 1047bb02e0acSNicolas Bonnefon output = defaultLocale.toString( humanSize, 'f', 1 ); 1048bb02e0acSNicolas Bonnefon 1049bb02e0acSNicolas Bonnefon output += QString(" ") + sizeStrs[i]; 1050bb02e0acSNicolas Bonnefon 1051bb02e0acSNicolas Bonnefon return output; 1052bb02e0acSNicolas Bonnefon } 1053