Skip to content

Commit

Permalink
Display info when no data is available
Browse files Browse the repository at this point in the history
  • Loading branch information
crep4ever committed Oct 31, 2010
1 parent 13adc3c commit 2fe8d12
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 13 deletions.
Binary file added icons/attention.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions songbook.qrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>icons/patacrep.png</file>
<file>icons/attention.png</file>
</qresource>
</RCC>
10 changes: 7 additions & 3 deletions src/library.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,22 @@ void CLibrary::setPathToSongs(const QString path)
m_pathToSongs = path;
}
//------------------------------------------------------------------------------
void CLibrary::retrieveSongs()
bool CLibrary::retrieveSongs()
{
bool res = false;
QStringList filter;
filter << "*.sg";

QString path = QString("%1/songs/").arg(pathToSongs());
QDirIterator it(path, filter, QDir::NoFilter, QDirIterator::Subdirectories);

while(it.hasNext())
addSongFromFile(it.next());

{
res = true;
addSongFromFile(it.next());
}
submitAll();
return res;
}
//------------------------------------------------------------------------------
void CLibrary::addSongFromFile(const QString path)
Expand Down
3 changes: 2 additions & 1 deletion src/library.hh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public:
void setPathToSongs(const QString path);

public slots:
void retrieveSongs();
/// @return false if no song could be found
bool retrieveSongs();

public:
void addSongFromFile(const QString path);
Expand Down
38 changes: 29 additions & 9 deletions src/mainwindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
#include <QtGui>
#include <QtSql>
#include <QtAlgorithms>
#include <QDebug>

#include "label.hh"

#include "mainwindow.hh"
#include "preferences.hh"
#include "library.hh"
Expand All @@ -29,8 +29,6 @@
#include "download.hh"
#include "song-editor.hh"
#include "dialog-new-song.hh"

#include <QDebug>
//******************************************************************************
CMainWindow::CMainWindow()
: QMainWindow()
Expand Down Expand Up @@ -63,6 +61,21 @@ CMainWindow::CMainWindow()
m_log->setMaximumHeight(150);
m_log->setReadOnly(true);

// no data info widget
m_noDataInfo = new QTextEdit;
m_noDataInfo->setReadOnly(true);
m_noDataInfo->setMaximumHeight(150);
m_noDataInfo->setHtml(QString(tr("<table><tr><td valign=middle> "
"<img src=\":/icons/attention.png\" /> </td><td>"
"<p>The directory <b>%1</b> does not contain any song file (\".sg\").<br/><br/> "
"You may :<ul><li>select a valid directory in the menu <i>Edit/Preferences</i></li>"
"<li>use the menu <i>Library/Download</i> to get the latest git snapshot</li>"
"<li>manually download the latest tarball on "
"<a href=\"http://www.patacrep.com/static1/downloads\">"
"patacrep.com</a></li></ul>"
"</p></td></tr></table>")).arg(workingPath()));
m_noDataInfo->hide();

// toolbar (for the build button)
m_toolbar = new QToolBar;
m_toolbar->setMovable(false);
Expand All @@ -78,8 +91,8 @@ CMainWindow::CMainWindow()
m_toolbar->addAction(m_buildAct);

//Connection to database
if (!connectDb())
refreshLibrary(); //database did not exist
connectDb();
refreshLibrary();

// initialize the filtering proxy
m_proxyModel->setDynamicSortFilter(true);
Expand Down Expand Up @@ -111,8 +124,9 @@ CMainWindow::CMainWindow()
horizontalLayout->addStretch();
horizontalLayout->addLayout(filterLayout);

// Main widgets
//Layouts
QBoxLayout *mainLayout = new QVBoxLayout;
QBoxLayout *dataLayout = new QVBoxLayout;
QBoxLayout *centerLayout = new QHBoxLayout;
QBoxLayout *leftLayout = new QVBoxLayout;
leftLayout->addWidget(new QLabel(tr("<b>Songbook</b>")));
Expand All @@ -125,9 +139,11 @@ CMainWindow::CMainWindow()
leftLayout->addWidget(createSongInfoWidget());
leftLayout->setStretch(1,4);
leftLayout->setStretch(3,1);
dataLayout->addWidget(m_view);
dataLayout->addWidget(m_noDataInfo);
centerLayout->addLayout(leftLayout);
centerLayout->setStretch(0,1);
centerLayout->addWidget(m_view);
centerLayout->addLayout(dataLayout);
centerLayout->setStretch(1,2);
mainLayout->addLayout(centerLayout);
mainLayout->addWidget(m_log);
Expand Down Expand Up @@ -335,7 +351,7 @@ void CMainWindow::createActions()
connect(m_refreshLibraryAct, SIGNAL(triggered()), this, SLOT(refreshLibrary()));

m_rebuildLibraryAct = new QAction(tr("Rebuild"), this);
m_refreshLibraryAct->setStatusTip(tr("Rebuild the current song list from \".sg\" files"));
m_rebuildLibraryAct->setStatusTip(tr("Rebuild the current song list from \".sg\" files"));
connect(m_rebuildLibraryAct, SIGNAL(triggered()), this, SLOT(rebuildLibrary()));

m_downloadDbAct = new QAction(tr("Download"),this);
Expand Down Expand Up @@ -443,9 +459,13 @@ bool CMainWindow::connectDb()
//------------------------------------------------------------------------------
void CMainWindow::refreshLibrary()
{
m_noDataInfo->hide();

// Retrieve all songs from .sg files in working dir
m_library->setPathToSongs(workingPath());
m_library->retrieveSongs();
if(!m_library->retrieveSongs())
m_noDataInfo->show();

m_view->sortByColumn(1, Qt::AscendingOrder);
m_view->sortByColumn(0, Qt::AscendingOrder);
m_view->show();
Expand Down
1 change: 1 addition & 0 deletions src/mainwindow.hh
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ private:
CTabWidget* m_mainWidget;
QTableView *m_view;
QProgressBar* m_progressBar;
QTextEdit* m_noDataInfo;

// Global
QString m_workingPath;
Expand Down

0 comments on commit 2fe8d12

Please sign in to comment.