From 6b68598d1dc7488d75cf548da4853a99d933a925 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Sun, 4 Mar 2012 21:53:57 -0500 Subject: [PATCH] Show job status for indexing --- src/libtomahawk/CMakeLists.txt | 2 + .../databasecommand_updatesearchindex.cpp | 14 +++++- .../databasecommand_updatesearchindex.h | 4 ++ src/libtomahawk/jobview/IndexingJobItem.cpp | 47 +++++++++++++++++++ src/libtomahawk/jobview/IndexingJobItem.h | 39 +++++++++++++++ 5 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 src/libtomahawk/jobview/IndexingJobItem.cpp create mode 100644 src/libtomahawk/jobview/IndexingJobItem.h diff --git a/src/libtomahawk/CMakeLists.txt b/src/libtomahawk/CMakeLists.txt index 7aa75f2ef..55fbc8da8 100644 --- a/src/libtomahawk/CMakeLists.txt +++ b/src/libtomahawk/CMakeLists.txt @@ -39,6 +39,7 @@ set( libGuiSources jobview/TransferStatusItem.cpp jobview/LatchedStatusItem.cpp jobview/ErrorStatusMessage.cpp + jobview/IndexingJobItem.cpp infobar/infobar.cpp @@ -278,6 +279,7 @@ set( libGuiHeaders jobview/TransferStatusItem.h jobview/LatchedStatusItem.h jobview/ErrorStatusMessage.h + jobview/IndexingJobItem.h thirdparty/Qocoa/qsearchfield.h ) diff --git a/src/libtomahawk/database/databasecommand_updatesearchindex.cpp b/src/libtomahawk/database/databasecommand_updatesearchindex.cpp index bd8c81f76..ee1920608 100644 --- a/src/libtomahawk/database/databasecommand_updatesearchindex.cpp +++ b/src/libtomahawk/database/databasecommand_updatesearchindex.cpp @@ -21,14 +21,26 @@ #include "databaseimpl.h" #include "tomahawksqlquery.h" #include "utils/logger.h" +#include "jobview/IndexingJobItem.h" +#include "jobview/JobStatusView.h" +#include "jobview/JobStatusModel.h" #include DatabaseCommand_UpdateSearchIndex::DatabaseCommand_UpdateSearchIndex() : DatabaseCommand() + , m_statusJob( new IndexingJobItem ) { tLog() << Q_FUNC_INFO << "Updating index."; + + JobStatusView::instance()->model()->addJob( m_statusJob ); +} + + +DatabaseCommand_UpdateSearchIndex::~DatabaseCommand_UpdateSearchIndex() +{ + m_statusJob->done(); } @@ -48,7 +60,7 @@ DatabaseCommand_UpdateSearchIndex::indexTable( DatabaseImpl* db, const QString& value = ""; for ( int v = 1; v < q.record().count(); v++ ) value += q.value( v ).toString() + " "; - + fields.insert( q.value( 0 ).toUInt(), value.trimmed() ); } diff --git a/src/libtomahawk/database/databasecommand_updatesearchindex.h b/src/libtomahawk/database/databasecommand_updatesearchindex.h index daa5abbf2..5698cda7e 100644 --- a/src/libtomahawk/database/databasecommand_updatesearchindex.h +++ b/src/libtomahawk/database/databasecommand_updatesearchindex.h @@ -22,11 +22,14 @@ #include "databasecommand.h" #include "dllmacro.h" +class IndexingJobItem; + class DLLEXPORT DatabaseCommand_UpdateSearchIndex : public DatabaseCommand { Q_OBJECT public: explicit DatabaseCommand_UpdateSearchIndex(); + virtual ~DatabaseCommand_UpdateSearchIndex(); virtual QString commandname() const { return "updatesearchindex"; } virtual bool doesMutates() const { return true; } @@ -39,6 +42,7 @@ private: void indexTable( DatabaseImpl* db, const QString& table, const QString& query ); QString table; + IndexingJobItem* m_statusJob; }; #endif // DATABASECOMMAND_UPDATESEARCHINDEX_H diff --git a/src/libtomahawk/jobview/IndexingJobItem.cpp b/src/libtomahawk/jobview/IndexingJobItem.cpp new file mode 100644 index 000000000..dc4634c64 --- /dev/null +++ b/src/libtomahawk/jobview/IndexingJobItem.cpp @@ -0,0 +1,47 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Leo Franchi + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#include "IndexingJobItem.h" + +#include "utils/tomahawkutils.h" + +static QPixmap* s_indexIcon = 0; + + +QString +IndexingJobItem::mainText() const +{ + return tr( "Indexing database" ); +} + +QPixmap +IndexingJobItem::icon() const +{ + if ( s_indexIcon == 0 ) + s_indexIcon = new QPixmap( RESPATH "images/view-refresh.png" ); + + return *s_indexIcon; + +} + + +void IndexingJobItem::done() +{ + emit finished(); +} + diff --git a/src/libtomahawk/jobview/IndexingJobItem.h b/src/libtomahawk/jobview/IndexingJobItem.h new file mode 100644 index 000000000..61bf5a05f --- /dev/null +++ b/src/libtomahawk/jobview/IndexingJobItem.h @@ -0,0 +1,39 @@ +/* === This file is part of Tomahawk Player - === + * + * Copyright 2010-2011, Leo Franchi + * + * Tomahawk is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Tomahawk is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Tomahawk. If not, see . + */ + +#ifndef INDEXINGJOBITEM_H +#define INDEXINGJOBITEM_H + +#include + + +class IndexingJobItem : public JobStatusItem +{ + Q_OBJECT +public: + explicit IndexingJobItem() {} + + void done(); + + virtual QString rightColumnText() const { return QString(); } + virtual QString mainText() const; + virtual QPixmap icon() const; + virtual QString type() const { return "indexerjob"; } +}; + +#endif // INDEXINGJOBITEM_H