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 105*b297d2f4SNicolas Bonnefon signalMux_.connect( SIGNAL( followModeChanged( bool ) ), 106*b297d2f4SNicolas 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& ) ) ); 15909aff35dSNicolas Bonnefon 160f109b95bSNicolas Bonnefon #ifdef GLOGG_SUPPORTS_VERSION_CHECKING 161460de700SNicolas Bonnefon // Version checker notification 162460de700SNicolas Bonnefon connect( &versionChecker_, SIGNAL( newVersionFound( const QString& ) ), 163460de700SNicolas Bonnefon this, SLOT( newVersionNotification( const QString& ) ) ); 164f109b95bSNicolas Bonnefon #endif 165460de700SNicolas Bonnefon 166b423cd88SNicolas Bonnefon // Construct the QuickFind bar 167b423cd88SNicolas Bonnefon quickFindWidget_.hide(); 168b423cd88SNicolas Bonnefon 169b423cd88SNicolas Bonnefon QWidget* central_widget = new QWidget(); 170b423cd88SNicolas Bonnefon QVBoxLayout* main_layout = new QVBoxLayout(); 171548acbf6SNicolas Bonnefon main_layout->setContentsMargins( 0, 0, 0, 0 ); 172b423cd88SNicolas Bonnefon main_layout->addWidget( &mainTabWidget_ ); 173b423cd88SNicolas Bonnefon main_layout->addWidget( &quickFindWidget_ ); 174b423cd88SNicolas Bonnefon central_widget->setLayout( main_layout ); 175b423cd88SNicolas Bonnefon 176b423cd88SNicolas Bonnefon setCentralWidget( central_widget ); 177bb02e0acSNicolas Bonnefon } 178bb02e0acSNicolas Bonnefon 1798964a9adSNicolas Bonnefon void MainWindow::reloadSession() 1808964a9adSNicolas Bonnefon { 181b76966a6SNicolas Bonnefon QByteArray geometry; 182b76966a6SNicolas Bonnefon 183b76966a6SNicolas Bonnefon session_->storedGeometry( &geometry ); 184b76966a6SNicolas Bonnefon restoreGeometry( geometry ); 185b76966a6SNicolas Bonnefon 1868964a9adSNicolas Bonnefon int current_file_index = -1; 1878964a9adSNicolas Bonnefon 1888964a9adSNicolas Bonnefon for ( auto open_file: session_->restore( 1898964a9adSNicolas Bonnefon []() { return new CrawlerWidget(); }, 1908964a9adSNicolas Bonnefon ¤t_file_index ) ) 1918964a9adSNicolas Bonnefon { 1928964a9adSNicolas Bonnefon QString file_name = { open_file.first.c_str() }; 1938964a9adSNicolas Bonnefon CrawlerWidget* crawler_widget = dynamic_cast<CrawlerWidget*>( 1948964a9adSNicolas Bonnefon open_file.second ); 1958964a9adSNicolas Bonnefon 1968964a9adSNicolas Bonnefon assert( crawler_widget ); 1978964a9adSNicolas Bonnefon 1988964a9adSNicolas Bonnefon mainTabWidget_.addTab( crawler_widget, strippedName( file_name ) ); 1998964a9adSNicolas Bonnefon } 2008964a9adSNicolas Bonnefon 2018964a9adSNicolas Bonnefon if ( current_file_index >= 0 ) 2028964a9adSNicolas Bonnefon mainTabWidget_.setCurrentIndex( current_file_index ); 2038964a9adSNicolas Bonnefon } 2048964a9adSNicolas Bonnefon 205bb02e0acSNicolas Bonnefon void MainWindow::loadInitialFile( QString fileName ) 206bb02e0acSNicolas Bonnefon { 207bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "loadInitialFile"; 208bb02e0acSNicolas Bonnefon 209bb02e0acSNicolas Bonnefon // Is there a file passed as argument? 210bb02e0acSNicolas Bonnefon if ( !fileName.isEmpty() ) 211bb02e0acSNicolas Bonnefon loadFile( fileName ); 212bb02e0acSNicolas Bonnefon } 213bb02e0acSNicolas Bonnefon 2148a9275b2SNicolas Bonnefon void MainWindow::startBackgroundTasks() 2158a9275b2SNicolas Bonnefon { 2168a9275b2SNicolas Bonnefon LOG(logDEBUG) << "startBackgroundTasks"; 217431d01deSNicolas Bonnefon 218431d01deSNicolas Bonnefon #ifdef GLOGG_SUPPORTS_VERSION_CHECKING 219431d01deSNicolas Bonnefon versionChecker_.startCheck(); 220431d01deSNicolas Bonnefon #endif 2218a9275b2SNicolas Bonnefon } 2228a9275b2SNicolas Bonnefon 223bb02e0acSNicolas Bonnefon // 224bb02e0acSNicolas Bonnefon // Private functions 225bb02e0acSNicolas Bonnefon // 226bb02e0acSNicolas Bonnefon 227bb02e0acSNicolas Bonnefon // Menu actions 228bb02e0acSNicolas Bonnefon void MainWindow::createActions() 229bb02e0acSNicolas Bonnefon { 23011582726SNicolas Bonnefon std::shared_ptr<Configuration> config = 23111582726SNicolas Bonnefon Persistent<Configuration>( "settings" ); 232bb02e0acSNicolas Bonnefon 233bb02e0acSNicolas Bonnefon openAction = new QAction(tr("&Open..."), this); 234bb02e0acSNicolas Bonnefon openAction->setShortcut(QKeySequence::Open); 235bb02e0acSNicolas Bonnefon openAction->setIcon( QIcon(":/images/open16.png") ); 236bb02e0acSNicolas Bonnefon openAction->setStatusTip(tr("Open a file")); 237bb02e0acSNicolas Bonnefon connect(openAction, SIGNAL(triggered()), this, SLOT(open())); 238bb02e0acSNicolas Bonnefon 23963dc3514SGustav Andersson closeAction = new QAction(tr("&Close"), this); 24004325d43SGustav Andersson closeAction->setShortcut(tr("Ctrl+W")); 24163dc3514SGustav Andersson closeAction->setStatusTip(tr("Close document")); 24263dc3514SGustav Andersson connect(closeAction, SIGNAL(triggered()), this, SLOT(closeTab())); 24363dc3514SGustav Andersson 24463dc3514SGustav Andersson closeAllAction = new QAction(tr("Close &All"), this); 24563dc3514SGustav Andersson closeAllAction->setStatusTip(tr("Close all documents")); 24663dc3514SGustav Andersson connect(closeAllAction, SIGNAL(triggered()), this, SLOT(closeAll())); 24763dc3514SGustav Andersson 248bb02e0acSNicolas Bonnefon // Recent files 249bb02e0acSNicolas Bonnefon for (int i = 0; i < MaxRecentFiles; ++i) { 250bb02e0acSNicolas Bonnefon recentFileActions[i] = new QAction(this); 251bb02e0acSNicolas Bonnefon recentFileActions[i]->setVisible(false); 252bb02e0acSNicolas Bonnefon connect(recentFileActions[i], SIGNAL(triggered()), 253bb02e0acSNicolas Bonnefon this, SLOT(openRecentFile())); 254bb02e0acSNicolas Bonnefon } 255bb02e0acSNicolas Bonnefon 256bb02e0acSNicolas Bonnefon exitAction = new QAction(tr("E&xit"), this); 257bb02e0acSNicolas Bonnefon exitAction->setShortcut(tr("Ctrl+Q")); 258bb02e0acSNicolas Bonnefon exitAction->setStatusTip(tr("Exit the application")); 259bb02e0acSNicolas Bonnefon connect( exitAction, SIGNAL(triggered()), this, SLOT(close()) ); 260bb02e0acSNicolas Bonnefon 261bb02e0acSNicolas Bonnefon copyAction = new QAction(tr("&Copy"), this); 262bb02e0acSNicolas Bonnefon copyAction->setShortcut(QKeySequence::Copy); 263bb02e0acSNicolas Bonnefon copyAction->setStatusTip(tr("Copy the selection")); 264bb02e0acSNicolas Bonnefon connect( copyAction, SIGNAL(triggered()), this, SLOT(copy()) ); 265bb02e0acSNicolas Bonnefon 266bb02e0acSNicolas Bonnefon selectAllAction = new QAction(tr("Select &All"), this); 267bb02e0acSNicolas Bonnefon selectAllAction->setShortcut(tr("Ctrl+A")); 268bb02e0acSNicolas Bonnefon selectAllAction->setStatusTip(tr("Select all the text")); 269bb02e0acSNicolas Bonnefon connect( selectAllAction, SIGNAL(triggered()), 270bb02e0acSNicolas Bonnefon this, SLOT( selectAll() ) ); 271bb02e0acSNicolas Bonnefon 272bb02e0acSNicolas Bonnefon findAction = new QAction(tr("&Find..."), this); 273bb02e0acSNicolas Bonnefon findAction->setShortcut(QKeySequence::Find); 274bb02e0acSNicolas Bonnefon findAction->setStatusTip(tr("Find the text")); 275bb02e0acSNicolas Bonnefon connect( findAction, SIGNAL(triggered()), 276bb02e0acSNicolas Bonnefon this, SLOT( find() ) ); 277bb02e0acSNicolas Bonnefon 278bb02e0acSNicolas Bonnefon overviewVisibleAction = new QAction( tr("Matches &overview"), this ); 279bb02e0acSNicolas Bonnefon overviewVisibleAction->setCheckable( true ); 28011582726SNicolas Bonnefon overviewVisibleAction->setChecked( config->isOverviewVisible() ); 281bb02e0acSNicolas Bonnefon connect( overviewVisibleAction, SIGNAL( toggled( bool ) ), 282bb02e0acSNicolas Bonnefon this, SLOT( toggleOverviewVisibility( bool )) ); 283bb02e0acSNicolas Bonnefon 284bb02e0acSNicolas Bonnefon lineNumbersVisibleInMainAction = 285bb02e0acSNicolas Bonnefon new QAction( tr("Line &numbers in main view"), this ); 286bb02e0acSNicolas Bonnefon lineNumbersVisibleInMainAction->setCheckable( true ); 28711582726SNicolas Bonnefon lineNumbersVisibleInMainAction->setChecked( config->mainLineNumbersVisible() ); 288bb02e0acSNicolas Bonnefon connect( lineNumbersVisibleInMainAction, SIGNAL( toggled( bool ) ), 289bb02e0acSNicolas Bonnefon this, SLOT( toggleMainLineNumbersVisibility( bool )) ); 290bb02e0acSNicolas Bonnefon 291bb02e0acSNicolas Bonnefon lineNumbersVisibleInFilteredAction = 292bb02e0acSNicolas Bonnefon new QAction( tr("Line &numbers in filtered view"), this ); 293bb02e0acSNicolas Bonnefon lineNumbersVisibleInFilteredAction->setCheckable( true ); 29411582726SNicolas Bonnefon lineNumbersVisibleInFilteredAction->setChecked( config->filteredLineNumbersVisible() ); 295bb02e0acSNicolas Bonnefon connect( lineNumbersVisibleInFilteredAction, SIGNAL( toggled( bool ) ), 296bb02e0acSNicolas Bonnefon this, SLOT( toggleFilteredLineNumbersVisibility( bool )) ); 297bb02e0acSNicolas Bonnefon 298bb02e0acSNicolas Bonnefon followAction = new QAction( tr("&Follow File"), this ); 299bb02e0acSNicolas Bonnefon followAction->setShortcut(Qt::Key_F); 300bb02e0acSNicolas Bonnefon followAction->setCheckable(true); 301bb02e0acSNicolas Bonnefon connect( followAction, SIGNAL(toggled( bool )), 302bb02e0acSNicolas Bonnefon this, SIGNAL(followSet( bool )) ); 303bb02e0acSNicolas Bonnefon 304bb02e0acSNicolas Bonnefon reloadAction = new QAction( tr("&Reload"), this ); 305bb02e0acSNicolas Bonnefon reloadAction->setShortcut(QKeySequence::Refresh); 306bb02e0acSNicolas Bonnefon reloadAction->setIcon( QIcon(":/images/reload16.png") ); 30732e44cfdSNicolas Bonnefon signalMux_.connect( reloadAction, SIGNAL(triggered()), SLOT(reload()) ); 308bb02e0acSNicolas Bonnefon 309bb02e0acSNicolas Bonnefon stopAction = new QAction( tr("&Stop"), this ); 310bb02e0acSNicolas Bonnefon stopAction->setIcon( QIcon(":/images/stop16.png") ); 3117875bde2SNicolas Bonnefon stopAction->setEnabled( true ); 3127847299cSNicolas Bonnefon signalMux_.connect( stopAction, SIGNAL(triggered()), SLOT(stopLoading()) ); 313bb02e0acSNicolas Bonnefon 314bb02e0acSNicolas Bonnefon filtersAction = new QAction(tr("&Filters..."), this); 315bb02e0acSNicolas Bonnefon filtersAction->setStatusTip(tr("Show the Filters box")); 316bb02e0acSNicolas Bonnefon connect( filtersAction, SIGNAL(triggered()), this, SLOT(filters()) ); 317bb02e0acSNicolas Bonnefon 318bb02e0acSNicolas Bonnefon optionsAction = new QAction(tr("&Options..."), this); 319bb02e0acSNicolas Bonnefon optionsAction->setStatusTip(tr("Show the Options box")); 320bb02e0acSNicolas Bonnefon connect( optionsAction, SIGNAL(triggered()), this, SLOT(options()) ); 321bb02e0acSNicolas Bonnefon 322bb02e0acSNicolas Bonnefon aboutAction = new QAction(tr("&About"), this); 323bb02e0acSNicolas Bonnefon aboutAction->setStatusTip(tr("Show the About box")); 324bb02e0acSNicolas Bonnefon connect( aboutAction, SIGNAL(triggered()), this, SLOT(about()) ); 325bb02e0acSNicolas Bonnefon 326bb02e0acSNicolas Bonnefon aboutQtAction = new QAction(tr("About &Qt"), this); 327bb02e0acSNicolas Bonnefon aboutAction->setStatusTip(tr("Show the Qt library's About box")); 328bb02e0acSNicolas Bonnefon connect( aboutQtAction, SIGNAL(triggered()), this, SLOT(aboutQt()) ); 329bb02e0acSNicolas Bonnefon } 330bb02e0acSNicolas Bonnefon 331bb02e0acSNicolas Bonnefon void MainWindow::createMenus() 332bb02e0acSNicolas Bonnefon { 333bb02e0acSNicolas Bonnefon fileMenu = menuBar()->addMenu( tr("&File") ); 334bb02e0acSNicolas Bonnefon fileMenu->addAction( openAction ); 33563dc3514SGustav Andersson fileMenu->addAction( closeAction ); 33663dc3514SGustav Andersson fileMenu->addAction( closeAllAction ); 337bb02e0acSNicolas Bonnefon fileMenu->addSeparator(); 338bb02e0acSNicolas Bonnefon for (int i = 0; i < MaxRecentFiles; ++i) { 339bb02e0acSNicolas Bonnefon fileMenu->addAction( recentFileActions[i] ); 340bb02e0acSNicolas Bonnefon recentFileActionBehaviors[i] = 341bb02e0acSNicolas Bonnefon new MenuActionToolTipBehavior(recentFileActions[i], fileMenu, this); 342bb02e0acSNicolas Bonnefon } 343bb02e0acSNicolas Bonnefon fileMenu->addSeparator(); 344bb02e0acSNicolas Bonnefon fileMenu->addAction( exitAction ); 345bb02e0acSNicolas Bonnefon 346bb02e0acSNicolas Bonnefon editMenu = menuBar()->addMenu( tr("&Edit") ); 347bb02e0acSNicolas Bonnefon editMenu->addAction( copyAction ); 348bb02e0acSNicolas Bonnefon editMenu->addAction( selectAllAction ); 349bb02e0acSNicolas Bonnefon editMenu->addSeparator(); 350bb02e0acSNicolas Bonnefon editMenu->addAction( findAction ); 351bb02e0acSNicolas Bonnefon 352bb02e0acSNicolas Bonnefon viewMenu = menuBar()->addMenu( tr("&View") ); 353bb02e0acSNicolas Bonnefon viewMenu->addAction( overviewVisibleAction ); 354bb02e0acSNicolas Bonnefon viewMenu->addSeparator(); 355bb02e0acSNicolas Bonnefon viewMenu->addAction( lineNumbersVisibleInMainAction ); 356bb02e0acSNicolas Bonnefon viewMenu->addAction( lineNumbersVisibleInFilteredAction ); 357bb02e0acSNicolas Bonnefon viewMenu->addSeparator(); 358bb02e0acSNicolas Bonnefon viewMenu->addAction( followAction ); 359bb02e0acSNicolas Bonnefon viewMenu->addSeparator(); 360bb02e0acSNicolas Bonnefon viewMenu->addAction( reloadAction ); 361bb02e0acSNicolas Bonnefon 362bb02e0acSNicolas Bonnefon toolsMenu = menuBar()->addMenu( tr("&Tools") ); 363bb02e0acSNicolas Bonnefon toolsMenu->addAction( filtersAction ); 364bb02e0acSNicolas Bonnefon toolsMenu->addSeparator(); 365bb02e0acSNicolas Bonnefon toolsMenu->addAction( optionsAction ); 366bb02e0acSNicolas Bonnefon 367bb02e0acSNicolas Bonnefon menuBar()->addSeparator(); 368bb02e0acSNicolas Bonnefon 369bb02e0acSNicolas Bonnefon helpMenu = menuBar()->addMenu( tr("&Help") ); 370bb02e0acSNicolas Bonnefon helpMenu->addAction( aboutAction ); 371bb02e0acSNicolas Bonnefon } 372bb02e0acSNicolas Bonnefon 373bb02e0acSNicolas Bonnefon void MainWindow::createToolBars() 374bb02e0acSNicolas Bonnefon { 375bb02e0acSNicolas Bonnefon infoLine = new InfoLine(); 376bb02e0acSNicolas Bonnefon infoLine->setFrameStyle( QFrame::WinPanel | QFrame::Sunken ); 377bb02e0acSNicolas Bonnefon infoLine->setLineWidth( 0 ); 378bb02e0acSNicolas Bonnefon 379bb02e0acSNicolas Bonnefon lineNbField = new QLabel( ); 380bb02e0acSNicolas Bonnefon lineNbField->setText( "Line 0" ); 381bb02e0acSNicolas Bonnefon lineNbField->setAlignment( Qt::AlignLeft | Qt::AlignVCenter ); 382bb02e0acSNicolas Bonnefon lineNbField->setMinimumSize( 383bb02e0acSNicolas Bonnefon lineNbField->fontMetrics().size( 0, "Line 0000000") ); 384bb02e0acSNicolas Bonnefon 385bb02e0acSNicolas Bonnefon toolBar = addToolBar( tr("&Toolbar") ); 386bb02e0acSNicolas Bonnefon toolBar->setIconSize( QSize( 16, 16 ) ); 387bb02e0acSNicolas Bonnefon toolBar->setMovable( false ); 388bb02e0acSNicolas Bonnefon toolBar->addAction( openAction ); 389bb02e0acSNicolas Bonnefon toolBar->addAction( reloadAction ); 390bb02e0acSNicolas Bonnefon toolBar->addWidget( infoLine ); 391bb02e0acSNicolas Bonnefon toolBar->addAction( stopAction ); 392bb02e0acSNicolas Bonnefon toolBar->addWidget( lineNbField ); 393bb02e0acSNicolas Bonnefon } 394bb02e0acSNicolas Bonnefon 395bb02e0acSNicolas Bonnefon // 396bb02e0acSNicolas Bonnefon // Slots 397bb02e0acSNicolas Bonnefon // 398bb02e0acSNicolas Bonnefon 399bb02e0acSNicolas Bonnefon // Opens the file selection dialog to select a new log file 400bb02e0acSNicolas Bonnefon void MainWindow::open() 401bb02e0acSNicolas Bonnefon { 402bb02e0acSNicolas Bonnefon QString defaultDir = "."; 403bb02e0acSNicolas Bonnefon 404bb02e0acSNicolas Bonnefon // Default to the path of the current file if there is one 4050e97f16dSNicolas Bonnefon if ( auto current = currentCrawlerWidget() ) 4060e97f16dSNicolas Bonnefon { 4070e97f16dSNicolas Bonnefon std::string current_file = session_->getFilename( current ); 4080e97f16dSNicolas Bonnefon QFileInfo fileInfo = QFileInfo( QString( current_file.c_str() ) ); 409bb02e0acSNicolas Bonnefon defaultDir = fileInfo.path(); 410bb02e0acSNicolas Bonnefon } 411bb02e0acSNicolas Bonnefon 412bb02e0acSNicolas Bonnefon QString fileName = QFileDialog::getOpenFileName(this, 413bb02e0acSNicolas Bonnefon tr("Open file"), defaultDir, tr("All files (*)")); 414bb02e0acSNicolas Bonnefon if (!fileName.isEmpty()) 415bb02e0acSNicolas Bonnefon loadFile(fileName); 416bb02e0acSNicolas Bonnefon } 417bb02e0acSNicolas Bonnefon 418bb02e0acSNicolas Bonnefon // Opens a log file from the recent files list 419bb02e0acSNicolas Bonnefon void MainWindow::openRecentFile() 420bb02e0acSNicolas Bonnefon { 421bb02e0acSNicolas Bonnefon QAction* action = qobject_cast<QAction*>(sender()); 422bb02e0acSNicolas Bonnefon if (action) 423bb02e0acSNicolas Bonnefon loadFile(action->data().toString()); 424bb02e0acSNicolas Bonnefon } 425bb02e0acSNicolas Bonnefon 42663dc3514SGustav Andersson // Close current tab 42763dc3514SGustav Andersson void MainWindow::closeTab() 42863dc3514SGustav Andersson { 42963dc3514SGustav Andersson int currentIndex = mainTabWidget_.currentIndex(); 43063dc3514SGustav Andersson 43163dc3514SGustav Andersson if ( currentIndex >= 0 ) 43263dc3514SGustav Andersson { 43363dc3514SGustav Andersson closeTab(currentIndex); 43463dc3514SGustav Andersson } 43563dc3514SGustav Andersson } 43663dc3514SGustav Andersson 43763dc3514SGustav Andersson // Close all tabs 43863dc3514SGustav Andersson void MainWindow::closeAll() 43963dc3514SGustav Andersson { 44063dc3514SGustav Andersson while ( mainTabWidget_.count() ) 44163dc3514SGustav Andersson { 44263dc3514SGustav Andersson closeTab(0); 44363dc3514SGustav Andersson } 44463dc3514SGustav Andersson } 44563dc3514SGustav Andersson 446bb02e0acSNicolas Bonnefon // Select all the text in the currently selected view 447bb02e0acSNicolas Bonnefon void MainWindow::selectAll() 448bb02e0acSNicolas Bonnefon { 44927ddfd3aSNicolas Bonnefon CrawlerWidget* current = currentCrawlerWidget(); 45027ddfd3aSNicolas Bonnefon 45127ddfd3aSNicolas Bonnefon if ( current ) 45227ddfd3aSNicolas Bonnefon current->selectAll(); 453bb02e0acSNicolas Bonnefon } 454bb02e0acSNicolas Bonnefon 455bb02e0acSNicolas Bonnefon // Copy the currently selected line into the clipboard 456bb02e0acSNicolas Bonnefon void MainWindow::copy() 457bb02e0acSNicolas Bonnefon { 458bb02e0acSNicolas Bonnefon static QClipboard* clipboard = QApplication::clipboard(); 45927ddfd3aSNicolas Bonnefon CrawlerWidget* current = currentCrawlerWidget(); 460bb02e0acSNicolas Bonnefon 46127ddfd3aSNicolas Bonnefon if ( current ) { 46227ddfd3aSNicolas Bonnefon clipboard->setText( current->getSelectedText() ); 463bb02e0acSNicolas Bonnefon 464bb02e0acSNicolas Bonnefon // Put it in the global selection as well (X11 only) 46527ddfd3aSNicolas Bonnefon clipboard->setText( current->getSelectedText(), 466bb02e0acSNicolas Bonnefon QClipboard::Selection ); 467bb02e0acSNicolas Bonnefon } 46827ddfd3aSNicolas Bonnefon } 469bb02e0acSNicolas Bonnefon 470bb02e0acSNicolas Bonnefon // Display the QuickFind bar 471bb02e0acSNicolas Bonnefon void MainWindow::find() 472bb02e0acSNicolas Bonnefon { 473b423cd88SNicolas Bonnefon displayQuickFindBar( QuickFindMux::Forward ); 474bb02e0acSNicolas Bonnefon } 475bb02e0acSNicolas Bonnefon 476bb02e0acSNicolas Bonnefon // Opens the 'Filters' dialog box 477bb02e0acSNicolas Bonnefon void MainWindow::filters() 478bb02e0acSNicolas Bonnefon { 479bb02e0acSNicolas Bonnefon FiltersDialog dialog(this); 48027ddfd3aSNicolas Bonnefon signalMux_.connect(&dialog, SIGNAL( optionsChanged() ), SLOT( applyConfiguration() )); 481bb02e0acSNicolas Bonnefon dialog.exec(); 48227ddfd3aSNicolas Bonnefon signalMux_.disconnect(&dialog, SIGNAL( optionsChanged() ), SLOT( applyConfiguration() )); 483bb02e0acSNicolas Bonnefon } 484bb02e0acSNicolas Bonnefon 485bb02e0acSNicolas Bonnefon // Opens the 'Options' modal dialog box 486bb02e0acSNicolas Bonnefon void MainWindow::options() 487bb02e0acSNicolas Bonnefon { 488bb02e0acSNicolas Bonnefon OptionsDialog dialog(this); 48927ddfd3aSNicolas Bonnefon signalMux_.connect(&dialog, SIGNAL( optionsChanged() ), SLOT( applyConfiguration() )); 490bb02e0acSNicolas Bonnefon dialog.exec(); 49127ddfd3aSNicolas Bonnefon signalMux_.disconnect(&dialog, SIGNAL( optionsChanged() ), SLOT( applyConfiguration() )); 492bb02e0acSNicolas Bonnefon } 493bb02e0acSNicolas Bonnefon 494bb02e0acSNicolas Bonnefon // Opens the 'About' dialog box. 495bb02e0acSNicolas Bonnefon void MainWindow::about() 496bb02e0acSNicolas Bonnefon { 497bb02e0acSNicolas Bonnefon QMessageBox::about(this, tr("About glogg"), 498bb02e0acSNicolas Bonnefon tr("<h2>glogg " GLOGG_VERSION "</h2>" 499bb02e0acSNicolas Bonnefon "<p>A fast, advanced log explorer." 500bb02e0acSNicolas Bonnefon #ifdef GLOGG_COMMIT 501bb02e0acSNicolas Bonnefon "<p>Built " GLOGG_DATE " from " GLOGG_COMMIT 502bb02e0acSNicolas Bonnefon #endif 50335c20658SNicolas Bonnefon "<p><a href=\"http://glogg.bonnefon.org/\">http://glogg.bonnefon.org/</a></p>" 504d022340fSNicolas Bonnefon "<p>Copyright © 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicolas Bonnefon and other contributors" 505bb02e0acSNicolas Bonnefon "<p>You may modify and redistribute the program under the terms of the GPL (version 3 or later)." ) ); 506bb02e0acSNicolas Bonnefon } 507bb02e0acSNicolas Bonnefon 508bb02e0acSNicolas Bonnefon // Opens the 'About Qt' dialog box. 509bb02e0acSNicolas Bonnefon void MainWindow::aboutQt() 510bb02e0acSNicolas Bonnefon { 511bb02e0acSNicolas Bonnefon } 512bb02e0acSNicolas Bonnefon 513bb02e0acSNicolas Bonnefon void MainWindow::toggleOverviewVisibility( bool isVisible ) 514bb02e0acSNicolas Bonnefon { 51511582726SNicolas Bonnefon std::shared_ptr<Configuration> config = 51611582726SNicolas Bonnefon Persistent<Configuration>( "settings" ); 51711582726SNicolas Bonnefon config->setOverviewVisible( isVisible ); 518bb02e0acSNicolas Bonnefon emit optionsChanged(); 519bb02e0acSNicolas Bonnefon } 520bb02e0acSNicolas Bonnefon 521bb02e0acSNicolas Bonnefon void MainWindow::toggleMainLineNumbersVisibility( bool isVisible ) 522bb02e0acSNicolas Bonnefon { 52311582726SNicolas Bonnefon std::shared_ptr<Configuration> config = 52411582726SNicolas Bonnefon Persistent<Configuration>( "settings" ); 52511582726SNicolas Bonnefon config->setMainLineNumbersVisible( isVisible ); 526bb02e0acSNicolas Bonnefon emit optionsChanged(); 527bb02e0acSNicolas Bonnefon } 528bb02e0acSNicolas Bonnefon 529bb02e0acSNicolas Bonnefon void MainWindow::toggleFilteredLineNumbersVisibility( bool isVisible ) 530bb02e0acSNicolas Bonnefon { 53111582726SNicolas Bonnefon std::shared_ptr<Configuration> config = 53211582726SNicolas Bonnefon Persistent<Configuration>( "settings" ); 53311582726SNicolas Bonnefon config->setFilteredLineNumbersVisible( isVisible ); 534bb02e0acSNicolas Bonnefon emit optionsChanged(); 535bb02e0acSNicolas Bonnefon } 536bb02e0acSNicolas Bonnefon 537*b297d2f4SNicolas Bonnefon void MainWindow::changeFollowMode( bool follow ) 538bb02e0acSNicolas Bonnefon { 539*b297d2f4SNicolas Bonnefon followAction->setChecked( follow ); 540bb02e0acSNicolas Bonnefon } 541bb02e0acSNicolas Bonnefon 542bb02e0acSNicolas Bonnefon void MainWindow::lineNumberHandler( int line ) 543bb02e0acSNicolas Bonnefon { 544bb02e0acSNicolas Bonnefon // The line number received is the internal (starts at 0) 545bb02e0acSNicolas Bonnefon lineNbField->setText( tr( "Line %1" ).arg( line + 1 ) ); 546bb02e0acSNicolas Bonnefon } 547bb02e0acSNicolas Bonnefon 548bb02e0acSNicolas Bonnefon void MainWindow::updateLoadingProgress( int progress ) 549bb02e0acSNicolas Bonnefon { 550bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "Loading progress: " << progress; 551bb02e0acSNicolas Bonnefon 552f8bd90d8SNicolas Bonnefon QString current_file = 553f8bd90d8SNicolas Bonnefon session_->getFilename( currentCrawlerWidget() ).c_str(); 5540e97f16dSNicolas Bonnefon 555bb02e0acSNicolas Bonnefon // We ignore 0% and 100% to avoid a flash when the file (or update) 556bb02e0acSNicolas Bonnefon // is very short. 557bb02e0acSNicolas Bonnefon if ( progress > 0 && progress < 100 ) { 558f8bd90d8SNicolas Bonnefon infoLine->setText( current_file + 559f8bd90d8SNicolas Bonnefon tr( " - Indexing lines... (%1 %)" ).arg( progress ) ); 560bb02e0acSNicolas Bonnefon infoLine->displayGauge( progress ); 561bb02e0acSNicolas Bonnefon 562bb02e0acSNicolas Bonnefon stopAction->setEnabled( true ); 563f8bd90d8SNicolas Bonnefon reloadAction->setEnabled( false ); 564bb02e0acSNicolas Bonnefon } 565bb02e0acSNicolas Bonnefon } 566bb02e0acSNicolas Bonnefon 567812146a8SNicolas Bonnefon void MainWindow::handleLoadingFinished( LoadingStatus status ) 568bb02e0acSNicolas Bonnefon { 569bb02e0acSNicolas Bonnefon QLocale defaultLocale; 570bb02e0acSNicolas Bonnefon 571812146a8SNicolas Bonnefon LOG(logDEBUG) << "handleLoadingFinished success=" << 572812146a8SNicolas Bonnefon ( status == LoadingStatus::Successful ); 573bb02e0acSNicolas Bonnefon 5740e97f16dSNicolas Bonnefon // No file is loading 5750e97f16dSNicolas Bonnefon loadingFileName.clear(); 5760e97f16dSNicolas Bonnefon 577812146a8SNicolas Bonnefon if ( status == LoadingStatus::Successful ) 578f8bd90d8SNicolas Bonnefon { 5790e97f16dSNicolas Bonnefon // Following should always work as we will only receive enter 5800e97f16dSNicolas Bonnefon // this slot if there is a crawler connected. 5810e97f16dSNicolas Bonnefon QString current_file = 5820e97f16dSNicolas Bonnefon session_->getFilename( currentCrawlerWidget() ).c_str(); 5830e97f16dSNicolas Bonnefon 5840a90ca6aSNicolas Bonnefon uint64_t fileSize; 5850a90ca6aSNicolas Bonnefon uint32_t fileNbLine; 586bb02e0acSNicolas Bonnefon QDateTime lastModified; 587bb02e0acSNicolas Bonnefon 58827ddfd3aSNicolas Bonnefon session_->getFileInfo( currentCrawlerWidget(), 5890a90ca6aSNicolas Bonnefon &fileSize, &fileNbLine, &lastModified ); 590bb02e0acSNicolas Bonnefon if ( lastModified.isValid() ) { 591bb02e0acSNicolas Bonnefon const QString date = 592bb02e0acSNicolas Bonnefon defaultLocale.toString( lastModified, QLocale::NarrowFormat ); 593bb02e0acSNicolas Bonnefon infoLine->setText( tr( "%1 (%2 - %3 lines - modified on %4)" ) 5940e97f16dSNicolas Bonnefon .arg(current_file).arg(readableSize(fileSize)) 595bb02e0acSNicolas Bonnefon .arg(fileNbLine).arg( date ) ); 596bb02e0acSNicolas Bonnefon } 597bb02e0acSNicolas Bonnefon else { 598bb02e0acSNicolas Bonnefon infoLine->setText( tr( "%1 (%2 - %3 lines)" ) 5990e97f16dSNicolas Bonnefon .arg(current_file).arg(readableSize(fileSize)) 600bb02e0acSNicolas Bonnefon .arg(fileNbLine) ); 601bb02e0acSNicolas Bonnefon } 602bb02e0acSNicolas Bonnefon 603bb02e0acSNicolas Bonnefon infoLine->hideGauge(); 604bb02e0acSNicolas Bonnefon stopAction->setEnabled( false ); 605f8bd90d8SNicolas Bonnefon reloadAction->setEnabled( true ); 6060a90ca6aSNicolas Bonnefon 6070a90ca6aSNicolas Bonnefon // Now everything is ready, we can finally show the file! 60827ddfd3aSNicolas Bonnefon currentCrawlerWidget()->show(); 609f8bd90d8SNicolas Bonnefon } 610f8bd90d8SNicolas Bonnefon else 611f8bd90d8SNicolas Bonnefon { 612812146a8SNicolas Bonnefon if ( status == LoadingStatus::NoMemory ) 613812146a8SNicolas Bonnefon { 614812146a8SNicolas Bonnefon QMessageBox alertBox; 615812146a8SNicolas Bonnefon alertBox.setText( "Not enough memory." ); 616812146a8SNicolas Bonnefon alertBox.setInformativeText( "The system does not have enough \ 617812146a8SNicolas Bonnefon memory to hold the index for this file. The file will now be closed." ); 618812146a8SNicolas Bonnefon alertBox.setIcon( QMessageBox::Critical ); 619812146a8SNicolas Bonnefon alertBox.exec(); 620812146a8SNicolas Bonnefon } 621812146a8SNicolas Bonnefon 622f8bd90d8SNicolas Bonnefon closeTab( mainTabWidget_.currentIndex() ); 623f8bd90d8SNicolas Bonnefon } 624f8bd90d8SNicolas Bonnefon 6257875bde2SNicolas Bonnefon // mainTabWidget_.setEnabled( true ); 626bb02e0acSNicolas Bonnefon } 627bb02e0acSNicolas Bonnefon 628f688be2eSNicolas Bonnefon void MainWindow::handleSearchRefreshChanged( int state ) 629f688be2eSNicolas Bonnefon { 630f688be2eSNicolas Bonnefon auto config = Persistent<Configuration>( "settings" ); 631f688be2eSNicolas Bonnefon config->setSearchAutoRefreshDefault( state == Qt::Checked ); 632f688be2eSNicolas Bonnefon } 633f688be2eSNicolas Bonnefon 634f688be2eSNicolas Bonnefon void MainWindow::handleIgnoreCaseChanged( int state ) 635f688be2eSNicolas Bonnefon { 636f688be2eSNicolas Bonnefon auto config = Persistent<Configuration>( "settings" ); 637f688be2eSNicolas Bonnefon config->setSearchIgnoreCaseDefault( state == Qt::Checked ); 638f688be2eSNicolas Bonnefon } 639f688be2eSNicolas Bonnefon 640cdd89779SNicolas Bonnefon void MainWindow::closeTab( int index ) 641cdd89779SNicolas Bonnefon { 642cdd89779SNicolas Bonnefon auto widget = dynamic_cast<CrawlerWidget*>( 643cdd89779SNicolas Bonnefon mainTabWidget_.widget( index ) ); 644cdd89779SNicolas Bonnefon 645cdd89779SNicolas Bonnefon assert( widget ); 646cdd89779SNicolas Bonnefon 647f8bd90d8SNicolas Bonnefon widget->stopLoading(); 648cdd89779SNicolas Bonnefon mainTabWidget_.removeTab( index ); 649cdd89779SNicolas Bonnefon session_->close( widget ); 650cdd89779SNicolas Bonnefon delete widget; 651cdd89779SNicolas Bonnefon } 652cdd89779SNicolas Bonnefon 653ee835f33SNicolas Bonnefon void MainWindow::currentTabChanged( int index ) 654ee835f33SNicolas Bonnefon { 655ee835f33SNicolas Bonnefon LOG(logDEBUG) << "currentTabChanged"; 656ee835f33SNicolas Bonnefon 657ee835f33SNicolas Bonnefon if ( index >= 0 ) 658ee835f33SNicolas Bonnefon { 659ee835f33SNicolas Bonnefon CrawlerWidget* crawler_widget = dynamic_cast<CrawlerWidget*>( 660ee835f33SNicolas Bonnefon mainTabWidget_.widget( index ) ); 661ee835f33SNicolas Bonnefon signalMux_.setCurrentDocument( crawler_widget ); 662ee835f33SNicolas Bonnefon quickFindMux_.registerSelector( crawler_widget ); 663ee835f33SNicolas Bonnefon 664ee835f33SNicolas Bonnefon // New tab is set up with fonts etc... 665ee835f33SNicolas Bonnefon emit optionsChanged(); 6660e97f16dSNicolas Bonnefon 6670e97f16dSNicolas Bonnefon // Update the title bar 6680e97f16dSNicolas Bonnefon updateTitleBar( QString( 6690e97f16dSNicolas Bonnefon session_->getFilename( crawler_widget ).c_str() ) ); 670ee835f33SNicolas Bonnefon } 671ee835f33SNicolas Bonnefon else 672ee835f33SNicolas Bonnefon { 673a1202e0cSNicolas Bonnefon // No tab left 674a1202e0cSNicolas Bonnefon signalMux_.setCurrentDocument( nullptr ); 675a1202e0cSNicolas Bonnefon quickFindMux_.registerSelector( nullptr ); 676a1202e0cSNicolas Bonnefon 677a1202e0cSNicolas Bonnefon infoLine->hideGauge(); 678a1202e0cSNicolas Bonnefon infoLine->clear(); 679a1202e0cSNicolas Bonnefon 680a1202e0cSNicolas Bonnefon updateTitleBar( QString() ); 681ee835f33SNicolas Bonnefon } 682ee835f33SNicolas Bonnefon } 683ee835f33SNicolas Bonnefon 6848570d8d2SNicolas Bonnefon void MainWindow::changeQFPattern( const QString& newPattern ) 6858570d8d2SNicolas Bonnefon { 6868570d8d2SNicolas Bonnefon quickFindWidget_.changeDisplayedPattern( newPattern ); 6878570d8d2SNicolas Bonnefon } 6888570d8d2SNicolas Bonnefon 68909aff35dSNicolas Bonnefon void MainWindow::loadFileNonInteractive( const QString& file_name ) 69009aff35dSNicolas Bonnefon { 69109aff35dSNicolas Bonnefon LOG(logDEBUG) << "loadFileNonInteractive( " 69209aff35dSNicolas Bonnefon << file_name.toStdString() << " )"; 69309aff35dSNicolas Bonnefon 69409aff35dSNicolas Bonnefon loadFile( file_name ); 69567cec333SNicolas Bonnefon 69667cec333SNicolas Bonnefon // Try to get the window to the front 69767cec333SNicolas Bonnefon // This is a bit of a hack but has been tested on: 69867cec333SNicolas Bonnefon // Qt 5.3 / Gnome / Linux 699cf609627SNicolas Bonnefon // Qt 4.8 / Win7 700cf609627SNicolas Bonnefon #ifdef _WIN32 701cf609627SNicolas Bonnefon // Hack copied from http://qt-project.org/forums/viewthread/6164 7028f46a826SNicolas Bonnefon ::SetWindowPos((HWND) effectiveWinId(), HWND_TOPMOST, 703cf609627SNicolas Bonnefon 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); 7048f46a826SNicolas Bonnefon ::SetWindowPos((HWND) effectiveWinId(), HWND_NOTOPMOST, 705cf609627SNicolas Bonnefon 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW); 706cf609627SNicolas Bonnefon #else 70767cec333SNicolas Bonnefon Qt::WindowFlags window_flags = windowFlags(); 70867cec333SNicolas Bonnefon window_flags |= Qt::WindowStaysOnTopHint; 70967cec333SNicolas Bonnefon setWindowFlags( window_flags ); 710cf609627SNicolas Bonnefon #endif 71167cec333SNicolas Bonnefon 71267cec333SNicolas Bonnefon activateWindow(); 71367cec333SNicolas Bonnefon raise(); 71467cec333SNicolas Bonnefon 715cf609627SNicolas Bonnefon #ifndef _WIN32 71667cec333SNicolas Bonnefon window_flags = windowFlags(); 71767cec333SNicolas Bonnefon window_flags &= ~Qt::WindowStaysOnTopHint; 71867cec333SNicolas Bonnefon setWindowFlags( window_flags ); 719cf609627SNicolas Bonnefon #endif 72067cec333SNicolas Bonnefon 721cf609627SNicolas Bonnefon showNormal(); 72209aff35dSNicolas Bonnefon } 72309aff35dSNicolas Bonnefon 724460de700SNicolas Bonnefon void MainWindow::newVersionNotification( const QString& new_version ) 725460de700SNicolas Bonnefon { 726460de700SNicolas Bonnefon LOG(logDEBUG) << "newVersionNotification( " << 727460de700SNicolas Bonnefon new_version.toStdString() << " )"; 728460de700SNicolas Bonnefon 729460de700SNicolas Bonnefon QMessageBox msgBox; 730460de700SNicolas Bonnefon msgBox.setText( QString( "A new version of glogg (%1) is available for download <p>" 731460de700SNicolas Bonnefon "<a href=\"http://glogg.bonnefon.org/download.html\">http://glogg.bonnefon.org/download.html</a>" 732460de700SNicolas Bonnefon ).arg( new_version ) ); 733460de700SNicolas Bonnefon msgBox.exec(); 734460de700SNicolas Bonnefon } 735460de700SNicolas Bonnefon 736bb02e0acSNicolas Bonnefon // 737bb02e0acSNicolas Bonnefon // Events 738bb02e0acSNicolas Bonnefon // 739bb02e0acSNicolas Bonnefon 740bb02e0acSNicolas Bonnefon // Closes the application 741bb02e0acSNicolas Bonnefon void MainWindow::closeEvent( QCloseEvent *event ) 742bb02e0acSNicolas Bonnefon { 743bb02e0acSNicolas Bonnefon writeSettings(); 744bb02e0acSNicolas Bonnefon event->accept(); 745bb02e0acSNicolas Bonnefon } 746bb02e0acSNicolas Bonnefon 747bb02e0acSNicolas Bonnefon // Accepts the drag event if it looks like a filename 748bb02e0acSNicolas Bonnefon void MainWindow::dragEnterEvent( QDragEnterEvent* event ) 749bb02e0acSNicolas Bonnefon { 750bb02e0acSNicolas Bonnefon if ( event->mimeData()->hasFormat( "text/uri-list" ) ) 751bb02e0acSNicolas Bonnefon event->acceptProposedAction(); 752bb02e0acSNicolas Bonnefon } 753bb02e0acSNicolas Bonnefon 754bb02e0acSNicolas Bonnefon // Tries and loads the file if the URL dropped is local 755bb02e0acSNicolas Bonnefon void MainWindow::dropEvent( QDropEvent* event ) 756bb02e0acSNicolas Bonnefon { 757bb02e0acSNicolas Bonnefon QList<QUrl> urls = event->mimeData()->urls(); 758bb02e0acSNicolas Bonnefon if ( urls.isEmpty() ) 759bb02e0acSNicolas Bonnefon return; 760bb02e0acSNicolas Bonnefon 761bb02e0acSNicolas Bonnefon QString fileName = urls.first().toLocalFile(); 762bb02e0acSNicolas Bonnefon if ( fileName.isEmpty() ) 763bb02e0acSNicolas Bonnefon return; 764bb02e0acSNicolas Bonnefon 765bb02e0acSNicolas Bonnefon loadFile( fileName ); 766bb02e0acSNicolas Bonnefon } 767bb02e0acSNicolas Bonnefon 7688570d8d2SNicolas Bonnefon void MainWindow::keyPressEvent( QKeyEvent* keyEvent ) 7698570d8d2SNicolas Bonnefon { 7708570d8d2SNicolas Bonnefon LOG(logDEBUG4) << "keyPressEvent received"; 7718570d8d2SNicolas Bonnefon 7728570d8d2SNicolas Bonnefon switch ( (keyEvent->text())[0].toLatin1() ) { 7738570d8d2SNicolas Bonnefon case '/': 7748570d8d2SNicolas Bonnefon displayQuickFindBar( QuickFindMux::Forward ); 7758570d8d2SNicolas Bonnefon break; 7768570d8d2SNicolas Bonnefon case '?': 7778570d8d2SNicolas Bonnefon displayQuickFindBar( QuickFindMux::Backward ); 7788570d8d2SNicolas Bonnefon break; 7798570d8d2SNicolas Bonnefon default: 7808570d8d2SNicolas Bonnefon keyEvent->ignore(); 7818570d8d2SNicolas Bonnefon } 7828570d8d2SNicolas Bonnefon 7838570d8d2SNicolas Bonnefon if ( !keyEvent->isAccepted() ) 7848570d8d2SNicolas Bonnefon QMainWindow::keyPressEvent( keyEvent ); 7858570d8d2SNicolas Bonnefon } 7868570d8d2SNicolas Bonnefon 787bb02e0acSNicolas Bonnefon // 788bb02e0acSNicolas Bonnefon // Private functions 789bb02e0acSNicolas Bonnefon // 790bb02e0acSNicolas Bonnefon 7910a90ca6aSNicolas Bonnefon // Create a CrawlerWidget for the passed file, start its loading 7920a90ca6aSNicolas Bonnefon // and update the title bar. 793bb02e0acSNicolas Bonnefon // The loading is done asynchronously. 794bb02e0acSNicolas Bonnefon bool MainWindow::loadFile( const QString& fileName ) 795bb02e0acSNicolas Bonnefon { 796bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "loadFile ( " << fileName.toStdString() << " )"; 797bb02e0acSNicolas Bonnefon 7983b4aad7fSNicolas Bonnefon // First check if the file is already open... 7993b4aad7fSNicolas Bonnefon CrawlerWidget* existing_crawler = dynamic_cast<CrawlerWidget*>( 8003b4aad7fSNicolas Bonnefon session_->getViewIfOpen( fileName.toStdString() ) ); 8013b4aad7fSNicolas Bonnefon if ( existing_crawler ) { 8023b4aad7fSNicolas Bonnefon // ... and switch to it. 8033b4aad7fSNicolas Bonnefon mainTabWidget_.setCurrentWidget( existing_crawler ); 8043b4aad7fSNicolas Bonnefon 8053b4aad7fSNicolas Bonnefon return true; 8063b4aad7fSNicolas Bonnefon } 8073b4aad7fSNicolas Bonnefon 808bb02e0acSNicolas Bonnefon // Load the file 809bb02e0acSNicolas Bonnefon loadingFileName = fileName; 810039481acSNicolas Bonnefon 811a3b56311SNicolas Bonnefon try { 81227ddfd3aSNicolas Bonnefon CrawlerWidget* crawler_widget = dynamic_cast<CrawlerWidget*>( 81327ddfd3aSNicolas Bonnefon session_->open( fileName.toStdString(), 8141b5e406eSNicolas Bonnefon []() { return new CrawlerWidget(); } ) ); 8151b5e406eSNicolas Bonnefon assert( crawler_widget ); 816f0708ca8SNicolas Bonnefon 8170a90ca6aSNicolas Bonnefon // We won't show the widget until the file is fully loaded 81827ddfd3aSNicolas Bonnefon crawler_widget->hide(); 819f0708ca8SNicolas Bonnefon 82027ddfd3aSNicolas Bonnefon // We disable the tab widget to avoid having someone switch 82127ddfd3aSNicolas Bonnefon // tab during loading. (maybe FIXME) 8227875bde2SNicolas Bonnefon //mainTabWidget_.setEnabled( false ); 823313a820fSNicolas Bonnefon 824a3b56311SNicolas Bonnefon int index = mainTabWidget_.addTab( 825a3b56311SNicolas Bonnefon crawler_widget, strippedName( fileName ) ); 826f0708ca8SNicolas Bonnefon 82727ddfd3aSNicolas Bonnefon // Setting the new tab, the user will see a blank page for the duration 82827ddfd3aSNicolas Bonnefon // of the loading, with no way to switch to another tab 82927ddfd3aSNicolas Bonnefon mainTabWidget_.setCurrentIndex( index ); 83027ddfd3aSNicolas Bonnefon 83160864ff5SNicolas Bonnefon // Update the recent files list 83260864ff5SNicolas Bonnefon // (reload the list first in case another glogg changed it) 83360864ff5SNicolas Bonnefon GetPersistentInfo().retrieve( "recentFiles" ); 83411582726SNicolas Bonnefon recentFiles_->addRecent( fileName ); 83560864ff5SNicolas Bonnefon GetPersistentInfo().save( "recentFiles" ); 83660864ff5SNicolas Bonnefon updateRecentFileActions(); 837a3b56311SNicolas Bonnefon } 838a3b56311SNicolas Bonnefon catch ( FileUnreadableErr ) { 839a3b56311SNicolas Bonnefon LOG(logDEBUG) << "Can't open file " << fileName.toStdString(); 840a3b56311SNicolas Bonnefon return false; 841a3b56311SNicolas Bonnefon } 84260864ff5SNicolas Bonnefon 843bb02e0acSNicolas Bonnefon LOG(logDEBUG) << "Success loading file " << fileName.toStdString(); 844bb02e0acSNicolas Bonnefon return true; 845a3b56311SNicolas Bonnefon 846bb02e0acSNicolas Bonnefon } 847bb02e0acSNicolas Bonnefon 848bb02e0acSNicolas Bonnefon // Strips the passed filename from its directory part. 849bb02e0acSNicolas Bonnefon QString MainWindow::strippedName( const QString& fullFileName ) const 850bb02e0acSNicolas Bonnefon { 851bb02e0acSNicolas Bonnefon return QFileInfo( fullFileName ).fileName(); 852bb02e0acSNicolas Bonnefon } 853bb02e0acSNicolas Bonnefon 85427ddfd3aSNicolas Bonnefon // Return the currently active CrawlerWidget, or NULL if none 85527ddfd3aSNicolas Bonnefon CrawlerWidget* MainWindow::currentCrawlerWidget() const 85627ddfd3aSNicolas Bonnefon { 85727ddfd3aSNicolas Bonnefon auto current = dynamic_cast<CrawlerWidget*>( 85827ddfd3aSNicolas Bonnefon mainTabWidget_.currentWidget() ); 85927ddfd3aSNicolas Bonnefon 86027ddfd3aSNicolas Bonnefon return current; 86127ddfd3aSNicolas Bonnefon } 86227ddfd3aSNicolas Bonnefon 8630e97f16dSNicolas Bonnefon // Update the title bar. 8640e97f16dSNicolas Bonnefon void MainWindow::updateTitleBar( const QString& file_name ) 865bb02e0acSNicolas Bonnefon { 866bb02e0acSNicolas Bonnefon QString shownName = tr( "Untitled" ); 8670e97f16dSNicolas Bonnefon if ( !file_name.isEmpty() ) 8680e97f16dSNicolas Bonnefon shownName = strippedName( file_name ); 869bb02e0acSNicolas Bonnefon 870bb02e0acSNicolas Bonnefon setWindowTitle( 871bb02e0acSNicolas Bonnefon tr("%1 - %2").arg(shownName).arg(tr("glogg")) 872bb02e0acSNicolas Bonnefon #ifdef GLOGG_COMMIT 873bb02e0acSNicolas Bonnefon + " (dev build " GLOGG_VERSION ")" 874bb02e0acSNicolas Bonnefon #endif 875bb02e0acSNicolas Bonnefon ); 876bb02e0acSNicolas Bonnefon } 877bb02e0acSNicolas Bonnefon 878bb02e0acSNicolas Bonnefon // Updates the actions for the recent files. 879bb02e0acSNicolas Bonnefon // Must be called after having added a new name to the list. 880bb02e0acSNicolas Bonnefon void MainWindow::updateRecentFileActions() 881bb02e0acSNicolas Bonnefon { 88211582726SNicolas Bonnefon QStringList recent_files = recentFiles_->recentFiles(); 883bb02e0acSNicolas Bonnefon 884bb02e0acSNicolas Bonnefon for ( int j = 0; j < MaxRecentFiles; ++j ) { 885bb02e0acSNicolas Bonnefon if ( j < recent_files.count() ) { 886bb02e0acSNicolas Bonnefon QString text = tr("&%1 %2").arg(j + 1).arg(strippedName(recent_files[j])); 887bb02e0acSNicolas Bonnefon recentFileActions[j]->setText( text ); 888bb02e0acSNicolas Bonnefon recentFileActions[j]->setToolTip( recent_files[j] ); 889bb02e0acSNicolas Bonnefon recentFileActions[j]->setData( recent_files[j] ); 890bb02e0acSNicolas Bonnefon recentFileActions[j]->setVisible( true ); 891bb02e0acSNicolas Bonnefon } 892bb02e0acSNicolas Bonnefon else { 893bb02e0acSNicolas Bonnefon recentFileActions[j]->setVisible( false ); 894bb02e0acSNicolas Bonnefon } 895bb02e0acSNicolas Bonnefon } 896bb02e0acSNicolas Bonnefon 897bb02e0acSNicolas Bonnefon // separatorAction->setVisible(!recentFiles.isEmpty()); 898bb02e0acSNicolas Bonnefon } 899bb02e0acSNicolas Bonnefon 900bb02e0acSNicolas Bonnefon // Write settings to permanent storage 901bb02e0acSNicolas Bonnefon void MainWindow::writeSettings() 902bb02e0acSNicolas Bonnefon { 903bb02e0acSNicolas Bonnefon // Save the session 904b57881faSNicolas Bonnefon // Generate the ordered list of widgets and their topLine 905a44d09bcSNicolas Bonnefon std::vector< 906a44d09bcSNicolas Bonnefon std::tuple<const ViewInterface*, uint64_t, std::shared_ptr<const ViewContextInterface>> 907a44d09bcSNicolas Bonnefon > widget_list; 908b57881faSNicolas Bonnefon for ( int i = 0; i < mainTabWidget_.count(); ++i ) 909a44d09bcSNicolas Bonnefon { 910a44d09bcSNicolas Bonnefon auto view = dynamic_cast<const ViewInterface*>( mainTabWidget_.widget( i ) ); 911a44d09bcSNicolas Bonnefon widget_list.push_back( std::make_tuple( 912a44d09bcSNicolas Bonnefon view, 913a44d09bcSNicolas Bonnefon 0UL, 914a44d09bcSNicolas Bonnefon view->context() ) ); 915a44d09bcSNicolas Bonnefon } 916b76966a6SNicolas Bonnefon session_->save( widget_list, saveGeometry() ); 917bb02e0acSNicolas Bonnefon 918bb02e0acSNicolas Bonnefon // User settings 919bb02e0acSNicolas Bonnefon GetPersistentInfo().save( QString( "settings" ) ); 920bb02e0acSNicolas Bonnefon } 921bb02e0acSNicolas Bonnefon 922bb02e0acSNicolas Bonnefon // Read settings from permanent storage 923bb02e0acSNicolas Bonnefon void MainWindow::readSettings() 924bb02e0acSNicolas Bonnefon { 925bb02e0acSNicolas Bonnefon // Get and restore the session 926b57881faSNicolas Bonnefon // GetPersistentInfo().retrieve( QString( "session" ) ); 927b57881faSNicolas Bonnefon // SessionInfo session = Persistent<SessionInfo>( "session" ); 9280a90ca6aSNicolas Bonnefon /* 9290a90ca6aSNicolas Bonnefon * FIXME: should be in the session 9300a90ca6aSNicolas Bonnefon crawlerWidget->restoreState( session.crawlerState() ); 9310a90ca6aSNicolas Bonnefon */ 932bb02e0acSNicolas Bonnefon 933bb02e0acSNicolas Bonnefon // History of recent files 934bb02e0acSNicolas Bonnefon GetPersistentInfo().retrieve( QString( "recentFiles" ) ); 935bb02e0acSNicolas Bonnefon updateRecentFileActions(); 936bb02e0acSNicolas Bonnefon 937b57881faSNicolas Bonnefon // GetPersistentInfo().retrieve( QString( "settings" ) ); 938bb02e0acSNicolas Bonnefon GetPersistentInfo().retrieve( QString( "filterSet" ) ); 939bb02e0acSNicolas Bonnefon } 940bb02e0acSNicolas Bonnefon 941b423cd88SNicolas Bonnefon void MainWindow::displayQuickFindBar( QuickFindMux::QFDirection direction ) 942b423cd88SNicolas Bonnefon { 943b423cd88SNicolas Bonnefon LOG(logDEBUG) << "MainWindow::displayQuickFindBar"; 944b423cd88SNicolas Bonnefon 9458570d8d2SNicolas Bonnefon // Warn crawlers so they can save the position of the focus in order 9468570d8d2SNicolas Bonnefon // to do incremental search in the right view. 9478570d8d2SNicolas Bonnefon emit enteringQuickFind(); 948b423cd88SNicolas Bonnefon 949b423cd88SNicolas Bonnefon quickFindMux_.setDirection( direction ); 950b423cd88SNicolas Bonnefon quickFindWidget_.userActivate(); 951b423cd88SNicolas Bonnefon } 952b423cd88SNicolas Bonnefon 953bb02e0acSNicolas Bonnefon // Returns the size in human readable format 9540a90ca6aSNicolas Bonnefon static QString readableSize( qint64 size ) 955bb02e0acSNicolas Bonnefon { 956bb02e0acSNicolas Bonnefon static const QString sizeStrs[] = { 9570a90ca6aSNicolas Bonnefon QObject::tr("B"), QObject::tr("KiB"), QObject::tr("MiB"), 9580a90ca6aSNicolas Bonnefon QObject::tr("GiB"), QObject::tr("TiB") }; 959bb02e0acSNicolas Bonnefon 960bb02e0acSNicolas Bonnefon QLocale defaultLocale; 961bb02e0acSNicolas Bonnefon unsigned int i; 962bb02e0acSNicolas Bonnefon double humanSize = size; 963bb02e0acSNicolas Bonnefon 964bb02e0acSNicolas Bonnefon for ( i=0; i+1 < (sizeof(sizeStrs)/sizeof(QString)) && (humanSize/1024.0) >= 1024.0; i++ ) 965bb02e0acSNicolas Bonnefon humanSize /= 1024.0; 966bb02e0acSNicolas Bonnefon 967bb02e0acSNicolas Bonnefon if ( humanSize >= 1024.0 ) { 968bb02e0acSNicolas Bonnefon humanSize /= 1024.0; 969bb02e0acSNicolas Bonnefon i++; 970bb02e0acSNicolas Bonnefon } 971bb02e0acSNicolas Bonnefon 972bb02e0acSNicolas Bonnefon QString output; 973bb02e0acSNicolas Bonnefon if ( i == 0 ) 974bb02e0acSNicolas Bonnefon // No decimal part if we display straight bytes. 975bb02e0acSNicolas Bonnefon output = defaultLocale.toString( (int) humanSize ); 976bb02e0acSNicolas Bonnefon else 977bb02e0acSNicolas Bonnefon output = defaultLocale.toString( humanSize, 'f', 1 ); 978bb02e0acSNicolas Bonnefon 979bb02e0acSNicolas Bonnefon output += QString(" ") + sizeStrs[i]; 980bb02e0acSNicolas Bonnefon 981bb02e0acSNicolas Bonnefon return output; 982bb02e0acSNicolas Bonnefon } 983