From aac13fd307ddaec2471451b97a118847e4f92ce2 Mon Sep 17 00:00:00 2001 From: Plamen Petrov Date: Sun, 3 Feb 2008 14:38:32 +0200 Subject: [PATCH] renamed kmk's config object from d to s, and made yet another part of kmk use the new RUNTIME DEBUG infrastructure --- src/kmk.cpp | 166 +++++++++++++++++++++++++++++++++++------------------------- src/kmk.h | 2 +- 2 files changed, 99 insertions(+), 69 deletions(-) diff --git a/src/kmk.cpp b/src/kmk.cpp index c7d882c..ada1297 100644 --- a/src/kmk.cpp +++ b/src/kmk.cpp @@ -56,12 +56,12 @@ kmk::kmk() : KMainWindow( 0, i18n("KDE Music Kataloger") ) { // allocate settings object - d = new KmkGlobalSettings; + s = new KmkGlobalSettings; // be safe here - Q_CHECK_PTR( d ); - if ( !d ) kdDebug() << "no mem for d!" << endl; + Q_CHECK_PTR( s ); + if ( !s ) kdDebug() << "no mem for s!" << endl; // if all is fine - then read the settings - d->readSettings( kapp->config() ); + s->readSettings( kapp->config() ); // save the caption - this one will be used when we need to restore it savedCaption = this->caption(); init_interface(); @@ -216,7 +216,7 @@ kmk::kmk() TagEditAction->plug( CSearchList_PopupMenu ); listTableLocateAction->plug( CSearchList_PopupMenu ); - if( d->dbg() & KMK_DBG_SIGNALS ) kdDebug() << "constructor: connecting signals to slots..." << endl; + if( s->dbg() & KMK_DBG_SIGNALS ) kdDebug() << "constructor: connecting signals to slots..." << endl; connect( treeListView, SIGNAL( contextMenuRequested( QListViewItem*, const QPoint &, int ) ), this, SLOT( slotTreeListViewPopupMenuRequested( QListViewItem*, const QPoint &, int ) ) ); @@ -235,7 +235,7 @@ kmk::kmk() connect( pbDone, SIGNAL( clicked() ), this, SLOT( slotDoneButtonClicked() ) ); - if( d->dbg() & KMK_DBG_SIGNALS ) kdDebug() << "constructor: done!" << endl; + if( s->dbg() & KMK_DBG_SIGNALS ) kdDebug() << "constructor: done!" << endl; FileSaveCalledFromFileSaveAs = FALSE; @@ -245,12 +245,12 @@ kmk::kmk() applyMainWindowSettings( kapp->config(), QString::fromLatin1("MainWindow") ); clearCatalogData(); - if ( d->loadLast() ) + if ( s->loadLast() ) { - if ( !d->lastCatalogUsed().isEmpty() ) + if ( !s->lastCatalogUsed().isEmpty() ) { show(); - loadCatalog( d->lastCatalogUsed() ); + loadCatalog( s->lastCatalogUsed() ); } } } @@ -397,20 +397,20 @@ void kmk::init_interface() kmk::~kmk() { saveMainWindowSettings( kapp->config(), QString::fromLatin1("MainWindow") ); - Q_CHECK_PTR( d ); + Q_CHECK_PTR( s ); switch ( CatalogState ) { case NoCatalog: - d->setLastCatalogUsed( "" ); + s->setLastCatalogUsed( "" ); break; case Modified: case Saved: - d->setLastCatalogUsed( catalogFileName ); + s->setLastCatalogUsed( catalogFileName ); break; default: break; } - d->saveSettings( kapp->config() ); + s->saveSettings( kapp->config() ); kapp->config()->setGroup( "GUI" ); kapp->config()->writeEntry( "splitter config", splitter1->sizes() ); @@ -420,7 +420,7 @@ kmk::~kmk() if (kmkProgress) delete ( kmkProgress ); if (kmkProgressTimer) delete ( kmkProgressTimer ); if (kmkSmooth) delete ( kmkSmooth ); - if ( d ) delete ( d ); + if ( s ) delete ( s ); } @@ -473,7 +473,7 @@ void kmk::slotFileNew() bytes_to_read_by_traverse( dirName ); if ( files_to_read ) { - if( d->dbg() & KMK_DBG_FS_OPS ) + if( s->dbg() & KMK_DBG_FS_OPS ) kdDebug() << "slotFileNew: Time elapsed: " << t.elapsed() << " ms, need to read: " << (bytes_to_read/(1024*1024)) << " MB, files to read: " << files_to_read << endl; @@ -487,7 +487,7 @@ void kmk::slotFileNew() traverse_tree( dirName ); // should update total_bytes as it scans setCatalogStateAndUpdate( Modified ); average_file_size = ( total_bytes/total_files ); - if( d->dbg() & KMK_DBG_FS_OPS & KMK_DBG_OTHER ) + if( s->dbg() & KMK_DBG_FS_OPS & KMK_DBG_OTHER ) { kdDebug() << "slotFileNew: Total time: " << t.elapsed() << " ms, read: " << (total_bytes/(1024*1024)) << " MB, files read: " << total_files << endl; @@ -543,9 +543,9 @@ void kmk::slotFileOpen() QString fileName = fd->selectedFile(); delete fd; qApp->processEvents(); loadCatalog( fileName ); - Q_CHECK_PTR( d ); - d->setLastCatalogUsed( fileName ); - d->saveSettings( kapp->config() ); + Q_CHECK_PTR( s ); + s->setLastCatalogUsed( fileName ); + s->saveSettings( kapp->config() ); } } @@ -583,7 +583,7 @@ void kmk::slotCatalogAddNewFolder() QTime t; t.start(); break_long_disk_operation = FALSE; bytes_to_read_by_traverse( dirName ); - if( d->dbg() & KMK_DBG_FS_OPS ) + if( s->dbg() & KMK_DBG_FS_OPS ) kdDebug() << "slotCatalogAddNewFolder: Time elapsed: " << t.elapsed() << " ms, need to read: " << (bytes_to_read/(1024*1024)) << " MB, files to read: " << files_to_read << endl; @@ -602,7 +602,7 @@ void kmk::slotCatalogAddNewFolder() total_bytes += bc01; total_files += bc02; total_folders += bc03; total_play_time += bc04; if ( total_files ) average_file_size = ( total_bytes/total_files ); - if( d->dbg() & KMK_DBG_FS_OPS & KMK_DBG_OTHER ) + if( s->dbg() & KMK_DBG_FS_OPS & KMK_DBG_OTHER ) { kdDebug() << "slotCatalogAddNewFolder:STATS: total_files = " << total_files << ";" << endl; kdDebug() << "slotCatalogAddNewFolder:STATS: total_folders = " << total_folders << ";" << endl; @@ -776,7 +776,7 @@ void kmk::closeEvent( QCloseEvent* ce ) { if( !ce ) { - if( d->dbg() & KMK_DBG_SIGNALS & KMK_DBG_OTHER ) + if( s->dbg() & KMK_DBG_SIGNALS & KMK_DBG_OTHER ) kdDebug() << "closeEvent: bad object" << endl; return; } @@ -806,10 +806,10 @@ void kmk::slotProgramSettings() // also, it internally calls exec() - so we only create it, passing relevant data // to its contructor uint * k = new uint; - d->saveSettings( kapp->config() ); + s->saveSettings( kapp->config() ); new kmkSettingsDialog( k ); // if( k ) // config changed? if so - re-read it.. - d->readSettings( kapp->config() ); + s->readSettings( kapp->config() ); player->handleConfigChange(); } @@ -840,7 +840,7 @@ void kmk::slotTagEdit() */ uint k = 0; new kmkTagEdit( files, &k ); - if( d->dbg() & KMK_DBG_SIGNALS & KMK_DBG_OTHER ) + if( s->dbg() & KMK_DBG_SIGNALS & KMK_DBG_OTHER ) kdDebug() << "slotTagEdit: TagEditDialog returns: " << k << endl; if( k ) { setCatalogStateAndUpdate( Modified ); @@ -1079,9 +1079,9 @@ void kmk::slotTreeListViewCurrentChanged( QListViewItem * itm ) // update table contets after manipulation filesListView->clearSelection(); // here we update the first 5 columns' width - Q_CHECK_PTR( d ); + Q_CHECK_PTR( s ); // honor user setting whether he/she wants auto-column-width, or likes speed more - if ( d->autoColumnWidth() ) + if ( s->autoColumnWidth() ) for ( ushort k=0; k<7; k++) filesListView->adjustColumn( k ); if ( sel_item ) { filesListView->ensureItemVisible( sel_item ); @@ -1231,9 +1231,9 @@ void kmk::slotSearchButtonClicked() // update table contets after manipulation searchFilesListView->clearSelection(); // here we update the first 5 columns' width - Q_CHECK_PTR( d ); + Q_CHECK_PTR( s ); // honor user setting whether he/she wants auto-column-width, or likes speed more - if ( d->autoColumnWidth() ) + if ( s->autoColumnWidth() ) for ( ushort k=0; k<7; k++) searchFilesListView->adjustColumn( k ); } searchFilesListView->setEnabled( TRUE ); @@ -1261,6 +1261,8 @@ void kmk::slotDoneButtonClicked() void kmk::clearCatalogData( const bool UpdateState ) { + if( s->dbg() & KMK_DBG_CAT_MEM_OPS ) + kdDebug() << "clearCatalogData: clearing all in-memory catalog data and stats...." << endl; // clear catalog tree MusicCatalog.clear(); treeListView->clear(); @@ -1276,10 +1278,27 @@ void kmk::clearCatalogData( const bool UpdateState ) total_folders = 0; total_play_time = 0; average_file_size = 0; // and finally, update state, title and actions accordingly if( UpdateState ) setCatalogStateAndUpdate( NoCatalog ); + if( s->dbg() & KMK_DBG_CAT_MEM_OPS ) + kdDebug() << "clearCatalogData: ...done!" << endl; } void kmk::setCatalogStateAndUpdate( const kmk::CatalogStateEnum state ) { + if( s->dbg() & KMK_DBG_OTHER ) + switch (state) { + case kmk::NoCatalog: + kdDebug() << "setCatalogStateAndUpdate: setting catalog state to \"NO CATALOG\"..." << endl; + break; + case kmk::Modified: + kdDebug() << "setCatalogStateAndUpdate: setting catalog state to \"MODIFIED\"..." << endl; + break; + case kmk::Saved: + kdDebug() << "setCatalogStateAndUpdate: setting catalog state to \"SAVED\"..." << endl; + break; + default: + kdDebug() << "setCatalogStateAndUpdate: setting catalog state to \"UNSPECIFIED\"..." << endl; + break; + } CatalogState = state; switch (state) { case kmk::NoCatalog: @@ -1337,6 +1356,8 @@ void kmk::setCatalogStateAndUpdate( const kmk::CatalogStateEnum state ) default: break; } + if( s->dbg() & KMK_DBG_OTHER ) + kdDebug() << "setCatalogStateAndUpdate: done!" << endl; } /* WARNING !!! OBSESIVE USE OF RECURSION!!!! @@ -1475,11 +1496,8 @@ unsigned long kmk::traverse_tree( const QString& dir ) using namespace TagLib; /* Use TagLib's functions to extract meta data and audio properties; This tells TagLib to read tags, and be as fast as possible */ -///@@@@@@@@@@@@@ -#ifdef _KMK_DEBUG__ -kdDebug() << " Now checking: " << d.filePath( fi2->fileName().latin1() ) << endl; -#endif -///@@@@@@@@@@@@@ + if( s->dbg() & KMK_DBG_FS_OPS ) + kdDebug() << "traverse_tree: Now checking: " << d.filePath( fi2->fileName().latin1() ) << endl; TagLib::FileRef f( d.filePath( fi2->fileName().latin1() ), TRUE, TagLib::AudioProperties::Fast ); /* If TagLib found the file to be valid - then add it to the catalog. Maybe here would be a good place to update some global catalog stats, @@ -1698,7 +1716,8 @@ MmData* kmk::findMmData( const QString& folder, const QString& filename ) if( ((*it).Folder().compare(folder)==0) && ((*it).FileName().compare(filename)==0) ) { found = TRUE; -// kdDebug()<<"called once: find MmData"<dbg() & KMK_DBG_CAT_MEM_OPS ) + kdDebug() << "findMmData: called once. " << endl; break; } } @@ -1751,6 +1770,8 @@ const bool kmk::catalog_has_dir( const QString & looked_for ) bool found = FALSE; MmDataList::iterator it; + if( s->dbg() & KMK_DBG_CAT_MEM_OPS ) + kdDebug() << "catalog_has_dir: Now will look for dir [" << looked_for << "]..." << endl; // QDir gives us paths ending on "/" and in the catalog - folders don't // end on "/"; so, strip that last slash "/" symbol QString stripped_looked_for = looked_for; @@ -1763,6 +1784,8 @@ const bool kmk::catalog_has_dir( const QString & looked_for ) if ( (*it).Folder().compare( stripped_looked_for )==0 ) { found = TRUE; + if( s->dbg() & KMK_DBG_CAT_MEM_OPS ) + kdDebug() << "catalog_has_dir: ...found! " << endl; break; } } @@ -1776,7 +1799,8 @@ void kmk::loadCatalog( const QString & fileName ) QDomDocument doc = QDomDocument::QDomDocument(); QFile file( fileName ); if ( !file.open( IO_ReadOnly | IO_Raw ) ) { - QMessageBox::warning( this, i18n("KDE Music Kataloger"),i18n("Could not open %1 for reading!").arg(fileName), + QMessageBox::warning( this, i18n("KDE Music Kataloger"), + i18n("Could not open %1 for reading!").arg(fileName), QMessageBox::Abort,QMessageBox::NoButton,QMessageBox::NoButton ); return; } @@ -1784,9 +1808,7 @@ void kmk::loadCatalog( const QString & fileName ) this->repaint(); qApp->processEvents(); // sleep( 5 ); kdDebug() << " sleeping..." << endl; QString xml_parse_err = "test"; int err_ln = 0; int err_cl = 0; -#ifdef _KMK_DEBUG__ QTime parse_time; parse_time.start(); -#endif if ( !doc.setContent( &file, TRUE, &xml_parse_err, &err_ln, &err_cl ) ) { file.close(); // qWarning( QString::number( *err_ln )+ " " + QString::number( *err_cl ) ); @@ -1798,10 +1820,10 @@ void kmk::loadCatalog( const QString & fileName ) return; } file.close(); -#ifdef _KMK_DEBUG__ - kdDebug() << "(kmk):parse_file(SAX2 parse): elapsed time: " << parse_time.elapsed() << " ms." << endl; + if( s->dbg() & KMK_DBG_CATALOG_IO ) + kdDebug() << "loadCatalog: parse_file(SAX2 parse): elapsed time: " + << parse_time.elapsed() << " ms." << endl; parse_time.restart(); -#endif clearCatalogData(); this->setCaption( i18n("Loading [%1]...").arg(fileName) ); catalogFileName = fileName; @@ -1825,11 +1847,10 @@ void kmk::loadCatalog( const QString & fileName ) } } } -#ifdef _KMK_DEBUG__ - kdDebug() << "(kmk):parse_file(new read): catalog version read time: " << parse_time.elapsed() << " ms." << endl; + if( s->dbg() & KMK_DBG_CATALOG_IO ) + kdDebug() << "loadCatalog: parse_file(new read): catalog version read time: " + << parse_time.elapsed() << " ms." << endl; parse_time.restart(); -#endif - if( process ) { ml = doc.elementsByTagName( "CatalogFile_Statistics" ); @@ -1850,10 +1871,10 @@ void kmk::loadCatalog( const QString & fileName ) if( !tx.isNull() ) average_file_size = (Q_ULLONG) tx.toDouble(); } } -#ifdef _KMK_DEBUG__ - kdDebug() << "(kmk):parse_file(new read): catalog stats read time: " << parse_time.elapsed() << " ms." << endl; + if( s->dbg() & KMK_DBG_CATALOG_IO ) + kdDebug() << "loadCatalog: parse_file(new read): catalog stats read time: " + << parse_time.elapsed() << " ms." << endl; parse_time.restart(); -#endif } /** READ THE FOLDERS STRUCTURE AUXILARY DATA - version, counters, etc */ @@ -1894,29 +1915,31 @@ void kmk::loadCatalog( const QString & fileName ) uint t = up.toUInt(); while( (t) && (CURRENT) ) { -//kdDebug() << i << ":going up from " << CURRENT->text(0) << "; parent() is: " << CURRENT->parent() << endl; CURRENT = (KListViewItem*)CURRENT->parent(); t--; } - if( t && (!warned) ) { KMessageBox::sorry( this, i18n("The catalog file you are trying to load is messed up. " + if( t && (!warned) ) { KMessageBox::sorry( this, + i18n("The catalog file you are trying to load is messed up. " "You get this message, so it passed XML sanity checks. That means almost for sure " "that it has been edited by hand - you are better off if you recreate it via Catalog->New. " "The scanning is fast enough anyway (around 10GB mp3 files scanned per minute)!\n" - "You have been warned - don't complain if something goes wrong."), i18n("KDE Music Kataloger") ); + "You have been warned - don't complain if something goes wrong."), + i18n("KDE Music Kataloger") ); warned = TRUE; } -//if(CURRENT) -// kdDebug() << i << ":(t="<text(0)<dbg() & KMK_DBG_OTHER ) + if(CURRENT) + kdDebug() << "loadCatalog: " << i << ":(t="<text(0)< "<text(0)<<"'s parent() is: " << CURRENT->parent() << endl; } } -#ifdef _KMK_DEBUG__ - kdDebug() << "(kmk):parse_file(new read): folder tree reconstruction time: " << parse_time.elapsed() << " ms." << endl; + if( s->dbg() & KMK_DBG_CATALOG_IO ) + kdDebug() << "loadCatalog: parse_file(new read): folder tree reconstruction time: " + << parse_time.elapsed() << " ms." << endl; parse_time.restart(); -#endif qApp->processEvents(); } @@ -1933,19 +1956,19 @@ void kmk::loadCatalog( const QString & fileName ) if( !tx.isNull() ) nodes_to_add = tx.toULong(); } } -#ifdef _KMK_DEBUG__ - kdDebug() << "(kmk):parse_file(new read): catalog objects count read time: " << parse_time.elapsed() << " ms." << endl; + if( s->dbg() & KMK_DBG_CATALOG_IO ) + kdDebug() << "loadCatalog: parse_file(new read): catalog objects count read time: " + << parse_time.elapsed() << " ms." << endl; parse_time.restart(); -#endif } /** READ ACTUAL AUDIO FILE DATA INTO MusicCatalog */ if( process ) { - ml = doc.elementsByTagName( "MObj" ); MmData node; + ml = doc.elementsByTagName( "MObj" ); MmData node; uint tags_found; for ( uint i = 0; iprocessEvents(); + MusicCatalog.append( node ); + if( s->dbg() & KMK_DBG_OTHER ) + kdDebug() << "loadCatalog: parse_file(new read): just added " << i << "-th object;" << endl; + } } -#ifdef _KMK_DEBUG__ - kdDebug() << "(kmk):parse_file(new read): node read and add time: " << parse_time.elapsed() << " ms." << endl; + if( s->dbg() & KMK_DBG_CATALOG_IO ) + kdDebug() << "loadCatalog: parse_file(new read): node read and add time: " + << parse_time.elapsed() << " ms." << endl; parse_time.restart(); -#endif } if( ! process ) - KMessageBox::sorry( this, i18n("No catalog markings found in [%1].\nThis can happen if the file is corrupt.") + KMessageBox::sorry( this, i18n("No catalog markings found in [%1].\n" + "This can happen if the file is corrupt.") .arg(catalogFileName),i18n("KDE Music Kataloger") ); else { setCatalogStateAndUpdate( Saved ); diff --git a/src/kmk.h b/src/kmk.h index ca47057..9d825b1 100644 --- a/src/kmk.h +++ b/src/kmk.h @@ -423,7 +423,7 @@ private: QString savedCaption; QString catalogFileName; - KmkGlobalSettings * d; + KmkGlobalSettings * s; KmkExtPlayer * player; protected: -- 2.11.4.GIT