File indexing completed on 2024-10-06 04:26:02
0001 /* 0002 SPDX-FileCopyrightText: 2003-2009 Sebastian Trueg <trueg@k3b.org> 0003 SPDX-FileCopyrightText: 2011 Michal Malek <michalm@jabster.pl> 0004 SPDX-FileCopyrightText: 1998-2009 Sebastian Trueg <trueg@k3b.org> 0005 0006 SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #include "k3bstatusbarmanager.h" 0010 #include "k3bcore.h" 0011 #include "k3bbusywidget.h" 0012 #include "k3b.h" 0013 #include "k3bversion.h" 0014 #include "k3bglobals.h" 0015 #include "k3bprojectmanager.h" 0016 #include "k3bapplication.h" 0017 #include "k3baudiodoc.h" 0018 #include "k3bdatadoc.h" 0019 #include "k3bmixeddoc.h" 0020 #include "k3bvcddoc.h" 0021 #include "k3bdiritem.h" 0022 #include "k3bview.h" 0023 0024 #include <KConfig> 0025 #include <KAboutData> 0026 #include <KIconLoader> 0027 #include <KLocalizedString> 0028 #include <KIO/Global> 0029 0030 #include <QFile> 0031 #include <QTimer> 0032 #include <QEvent> 0033 #include <QAction> 0034 #include <QLabel> 0035 #include <QStatusBar> 0036 #include <QToolTip> 0037 #include <QHBoxLayout> 0038 0039 0040 0041 K3b::StatusBarManager::StatusBarManager( K3b::MainWindow* parent ) 0042 : QObject(parent), 0043 m_mainWindow(parent) 0044 { 0045 // setup free temp space box 0046 QWidget* boxFreeTemp = new QWidget( m_mainWindow->statusBar() ); 0047 boxFreeTemp->installEventFilter( this ); 0048 m_pixFreeTemp = new QLabel( boxFreeTemp ); 0049 m_pixFreeTemp->setPixmap( QIcon::fromTheme("folder-green").pixmap(KIconLoader::SizeSmall) ); 0050 m_labelFreeTemp = new QLabel( boxFreeTemp ); 0051 0052 QHBoxLayout* boxFreeTempLayout = new QHBoxLayout( boxFreeTemp ); 0053 boxFreeTempLayout->setSpacing(2); 0054 boxFreeTempLayout->addWidget( new QLabel( i18n("Temp:"), boxFreeTemp ) ); 0055 boxFreeTempLayout->addWidget( m_pixFreeTemp ); 0056 boxFreeTempLayout->addWidget( m_labelFreeTemp ); 0057 0058 m_labelProjectInfo = new QLabel( m_mainWindow->statusBar() ); 0059 0060 // setup info area 0061 m_labelInfoMessage = new QLabel( " ", m_mainWindow->statusBar() ); 0062 0063 // setup version info 0064 m_versionBox = new QLabel( QString("K3b %1").arg(KAboutData::applicationData().version()), m_mainWindow->statusBar() ); 0065 m_versionBox->installEventFilter( this ); 0066 0067 // setup the statusbar 0068 m_mainWindow->statusBar()->addWidget( m_labelInfoMessage, 1 ); // for showing some info 0069 m_mainWindow->statusBar()->addPermanentWidget( m_labelProjectInfo, 0 ); 0070 // a spacer item 0071 m_mainWindow->statusBar()->addPermanentWidget( new QLabel( " ", m_mainWindow->statusBar() ), 0 ); 0072 m_mainWindow->statusBar()->addPermanentWidget( boxFreeTemp, 0 ); 0073 // a spacer item 0074 m_mainWindow->statusBar()->addPermanentWidget( new QLabel( " ", m_mainWindow->statusBar() ), 0 ); 0075 m_mainWindow->statusBar()->addPermanentWidget( m_versionBox, 0 ); 0076 // a spacer item 0077 m_mainWindow->statusBar()->addPermanentWidget( new QLabel( " ", m_mainWindow->statusBar() ), 0 ); 0078 0079 connect( m_mainWindow, SIGNAL(configChanged(KSharedConfig::Ptr)), 0080 this, SLOT(update()) ); 0081 connect( k3bappcore->projectManager(), SIGNAL(activeProjectChanged(K3b::Doc*)), 0082 this, SLOT(slotActiveProjectChanged(K3b::Doc*)) ); 0083 connect( k3bappcore->projectManager(), SIGNAL(projectChanged(K3b::Doc*)), 0084 this, SLOT(slotActiveProjectChanged(K3b::Doc*)) ); 0085 connect( (m_updateTimer = new QTimer( this )), SIGNAL(timeout()), 0086 this, SLOT(slotUpdateProjectStats()) ); 0087 0088 update(); 0089 } 0090 0091 0092 K3b::StatusBarManager::~StatusBarManager() 0093 { 0094 } 0095 0096 0097 void K3b::StatusBarManager::update() 0098 { 0099 QString path = K3b::defaultTempPath(); 0100 0101 if( !QFile::exists( path ) ) 0102 path.truncate( path.lastIndexOf('/') ); 0103 0104 unsigned long size, avail; 0105 if( K3b::kbFreeOnFs( path, size, avail ) ) { 0106 m_labelFreeTemp->setText(KIO::convertSizeFromKiB(avail) + '/' + 0107 KIO::convertSizeFromKiB(size) ); 0108 0109 // if we have less than 640 MB that is not good 0110 if( avail < 655360 ) 0111 m_pixFreeTemp->setPixmap( QIcon::fromTheme("folder-red").pixmap(KIconLoader::SizeSmall) ); 0112 else 0113 m_pixFreeTemp->setPixmap( QIcon::fromTheme("folder-green").pixmap(KIconLoader::SizeSmall) ); 0114 } else { 0115 m_labelFreeTemp->setText(i18n("No info")); 0116 } 0117 0118 if(path != m_labelFreeTemp->parentWidget()->toolTip()) 0119 m_labelFreeTemp->parentWidget()->setToolTip( path ); 0120 0121 // update the display every second 0122 QTimer::singleShot( 2000, this, SLOT(update()) ); 0123 } 0124 0125 0126 void K3b::StatusBarManager::showActionStatusText( const QString& text ) 0127 { 0128 m_mainWindow->statusBar()->showMessage( text ); 0129 } 0130 0131 0132 void K3b::StatusBarManager::clearActionStatusText() 0133 { 0134 m_mainWindow->statusBar()->clearMessage(); 0135 } 0136 0137 0138 bool K3b::StatusBarManager::eventFilter( QObject* o, QEvent* e ) 0139 { 0140 if( e->type() == QEvent::MouseButtonDblClick ) { 0141 if( o == m_labelFreeTemp->parentWidget() ) 0142 m_mainWindow->showOptionDialog( K3b::OptionDialog::Misc ); 0143 else if( o == m_versionBox ) 0144 #if QT_VERSION_MAJOR >= 6 0145 if( QAction* a = m_mainWindow->action( QStringLiteral("help_about_app") ) ) 0146 #else 0147 if( QAction* a = m_mainWindow->action( "help_about_app" ) ) 0148 #endif 0149 a->activate(QAction::Trigger); 0150 } 0151 0152 return QObject::eventFilter( o, e ); 0153 } 0154 0155 0156 static QString dataDocStats( K3b::DataDoc* dataDoc ) 0157 { 0158 return i18np( "One file in %2", 0159 "%1 files in %2", 0160 dataDoc->root()->numFiles(), 0161 i18np("one folder", "%1 folders", dataDoc->root()->numDirs()+1 ) ); 0162 } 0163 0164 0165 void K3b::StatusBarManager::slotActiveProjectChanged( K3b::Doc* doc ) 0166 { 0167 if( doc && doc == k3bappcore->projectManager()->activeProject() ) { 0168 // cache updates 0169 if( !m_updateTimer->isActive() ) { 0170 slotUpdateProjectStats(); 0171 m_updateTimer->setSingleShot( false ); 0172 m_updateTimer->start( 1000 ); 0173 } 0174 } 0175 else if( !doc ) { 0176 m_labelProjectInfo->setText( QString() ); 0177 } 0178 } 0179 0180 0181 void K3b::StatusBarManager::slotUpdateProjectStats() 0182 { 0183 K3b::Doc* doc = k3bappcore->projectManager()->activeProject(); 0184 if( doc ) { 0185 switch( doc->type() ) { 0186 case K3b::Doc::AudioProject: { 0187 K3b::AudioDoc* audioDoc = static_cast<K3b::AudioDoc*>( doc ); 0188 m_labelProjectInfo->setText( i18np("Audio CD (1 track)", "Audio CD (%1 tracks)", audioDoc->numOfTracks() ) ); 0189 break; 0190 } 0191 0192 case K3b::Doc::DataProject: { 0193 K3b::DataDoc* dataDoc = static_cast<K3b::DataDoc*>( doc ); 0194 m_labelProjectInfo->setText( i18n("Data Project (%1)",dataDocStats(dataDoc)) ); 0195 break; 0196 } 0197 0198 case K3b::Doc::MixedProject: { 0199 K3b::AudioDoc* audioDoc = static_cast<K3b::MixedDoc*>( doc )->audioDoc(); 0200 K3b::DataDoc* dataDoc = static_cast<K3b::MixedDoc*>( doc )->dataDoc(); 0201 m_labelProjectInfo->setText( i18np("Mixed CD (1 track and %2)", "Mixed CD (%1 tracks and %2)", audioDoc->numOfTracks(), 0202 dataDocStats(dataDoc)) ); 0203 break; 0204 } 0205 0206 case K3b::Doc::VcdProject: { 0207 K3b::VcdDoc* vcdDoc = static_cast<K3b::VcdDoc*>( doc ); 0208 m_labelProjectInfo->setText( i18np("Video CD (1 track)", "Video CD (%1 tracks)", vcdDoc->numOfTracks() ) ); 0209 break; 0210 } 0211 0212 case K3b::Doc::MovixProject: { 0213 K3b::DataDoc* dataDoc = static_cast<K3b::DataDoc*>( doc ); 0214 m_labelProjectInfo->setText( i18n("eMovix Project (%1)",dataDocStats(dataDoc)) ); 0215 break; 0216 } 0217 0218 case K3b::Doc::VideoDvdProject: { 0219 K3b::DataDoc* dataDoc = static_cast<K3b::DataDoc*>( doc ); 0220 m_labelProjectInfo->setText( i18n("Video DVD (%1)",dataDocStats(dataDoc)) ); 0221 break; 0222 } 0223 } 0224 } 0225 else { 0226 m_labelProjectInfo->setText( QString() ); 0227 } 0228 } 0229 0230 #include "moc_k3bstatusbarmanager.cpp"