View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0006764 | Scribus | Usability | public | 2008-02-14 23:20 | 2008-02-15 23:00 |
Reporter | arvee | Assigned To | fschmid | ||
Priority | normal | Severity | minor | Reproducibility | N/A |
Status | closed | Resolution | fixed | ||
Product Version | 1.3.5svn | ||||
Target Version | 1.3.5 | Fixed in Version | 1.3.5svn | ||
Summary | 0006764: Enhancements to Extras > Manage Images | ||||
Description | Search Images dialog. * enable/disable controls while searching * honour changes in the path edit box before searching and/or browsing * search base defaulted to last changed/edited path (in this scribus session) * caption/path parameters were swapped on QFileDialog::getExistingDirectory * public properties on PicSearchOptions that were only used/useful as getters are now private and wrapped in public getters. * refactored and documented a bit | ||||
Additional Information | files affected: picstatus.cpp picsearchoptions.cpp picsearchoptions.h picsearchoptions.ui | ||||
Tags | No tags attached. | ||||
Patch | |||||
2008-02-14 23:20
|
arvee-2008-02-14.diff (14,972 bytes)
Index: picsearchoptions.cpp =================================================================== --- picsearchoptions.cpp (revision 11652) +++ picsearchoptions.cpp (working copy) @@ -30,108 +30,169 @@ #include <QCheckBox> #include <QFileDialog> #include <QLabel> +#include <QDebug> + #include "picsearchoptions.h" #include "filesearch.h" -PicSearchOptions::PicSearchOptions(QWidget* parent, const QString & fileName, const QString & searchBase) : QDialog( parent ) -{ +PicSearchOptions::PicSearchOptions(QWidget* parent, const QString & fileName, const QString & searchBase) : QDialog(parent) { + setupUi(this); setModal(true); - m_fileName = fileName; - fileEdit->setText(fileName); - directoryEdit->setText(searchBase); + + m_bCancelled = false; + m_strFileName = fileName; + m_strLastDirSearched = searchBase; + + fileEdit->setText(m_strFileName); + directoryEdit->setText(m_strLastDirSearched); + progressBar1->hide(); searchLabel->hide(); - connect(startButton, SIGNAL(clicked()), this, SLOT(SearchPic())); - connect(changeDirButton, SIGNAL(clicked()), this, SLOT(changeSearchDir())); - caseInsensitiveCheck->setToolTip( "<qt>" + tr("The filesystem will be searched for case insensitive file names when you check this on. Remember it is not default on most operating systems except MS Windows") + "</qt>"); -} -void PicSearchOptions::setSearchButton(bool toCancel, const FileSearch* searcher) -{ - if (toCancel) - { - startButton->setText( tr("Cancel Search") ); + connect(startButton, SIGNAL(clicked()), this, SLOT(slotSearchPic())); + connect(changeDirButton, SIGNAL(clicked()), this, SLOT(slotChangeSearchDir())); + + caseInsensitiveCheck->setToolTip("<qt>" + tr("The filesystem will be searched for case insensitive file names when you check this on. Remember it is not default on most operating systems except MS Windows") + "</qt>"); + } + +void PicSearchOptions::setSearchButton(bool toCancel, const FileSearch* searcher) { + if (toCancel) { + startButton->setText(tr("Cancel Search")); + progressBar1->reset(); progressBar1->show(); searchLabel->show(); - disconnect(startButton, SIGNAL(clicked()), this, SLOT(SearchPic())); + + disconnect(startButton, SIGNAL(clicked()), this, SLOT(slotSearchPic())); connect(startButton, SIGNAL(clicked()), searcher, SLOT(cancel())); - } - else - { - startButton->setText( tr("Start Search")); + } + else { + startButton->setText(tr("Start Search")); + progressBar1->reset(); progressBar1->hide(); searchLabel->hide(); + disconnect(startButton, SIGNAL(clicked()), searcher, SLOT(cancel())); - connect(startButton, SIGNAL(clicked()), this, SLOT(SearchPic())); + connect(startButton, SIGNAL(clicked()), this, SLOT(slotSearchPic())); + } } -} -void PicSearchOptions::changeSearchDir() -{ - QString workDir; +void PicSearchOptions::slotChangeSearchDir() { + + QString workDir = directoryEdit->text(); + #ifndef _WIN32 - workDir = QDir::homePath(); + if (workDir.isEmpty() || !QDir().exists(workDir)) { + workDir = m_strLastDirSearched; + if (workDir.isEmpty() || !QDir().exists(workDir)) { + workDir = QDir::homePath(); + } + } +#else + // TODO: and on _WIN32 workDir is ... ? #endif - QString searchBase; - searchBase = QFileDialog::getExistingDirectory( this, workDir, tr("Select a base directory for search")); - if( searchBase.isEmpty() || !QDir().exists(searchBase) ) + + qDebug() << "PicSearchOptions: browsing for a new search folder from " << workDir; + + QString searchBase = QFileDialog::getExistingDirectory( + this, tr("Select a base directory for search"), workDir + ); + + if (searchBase.isEmpty() || !QDir().exists(searchBase)) { return; - directoryEdit->setText(searchBase); -} + } -void PicSearchOptions::SearchPic() -{ + m_strLastDirSearched = searchBase; + + directoryEdit->setText(m_strLastDirSearched); + } + +void PicSearchOptions::slotSearchPic() { + QString searchBase = directoryEdit->text(); - if( searchBase.isEmpty() || !QDir().exists(searchBase) ) - { - if (QMessageBox::warning(this, tr("Scribus - Image Search"), tr("Base directory for search does not exist.\nPlease choose another one."), - QMessageBox::Ok|QMessageBox::Default|QMessageBox::Escape|QMessageBox::Cancel, - QMessageBox::NoButton) != QMessageBox::Ok) + + if (searchBase.isEmpty() || !QDir().exists(searchBase)) { + if (QMessageBox::warning(this, tr("Scribus - Image Search"), + tr("Base directory for search does not exist.\nPlease choose another one."), + QMessageBox::Ok | QMessageBox::Default | QMessageBox::Escape | QMessageBox::Cancel, + QMessageBox::NoButton) != QMessageBox::Ok) { + // return; - changeSearchDir(); - if( searchBase.isEmpty() || !QDir().exists(searchBase) ) + } + + slotChangeSearchDir(); + + searchBase = directoryEdit->text(); + + if (searchBase.isEmpty() || !QDir().exists(searchBase)) return; - } + } + + m_strLastDirSearched = searchBase; + + qDebug() << "PicSearchOptions: searching for pics in " << m_strLastDirSearched; + // Set up the search, then return to the event loop until it notifies us // that it's done. // Note: search will be deleted when this PicStatus is, so there's no // need to worry about cleanup. // case sensitive note: it has no meaning on windows - int recurse = -1; - if (recursiveSearch->isChecked()) - recurse = -1; - else - recurse = 0; - FileSearch* search = new FileSearch(this, fileEdit->text(), searchBase, recurse, caseInsensitiveCheck->isChecked()); + int recurse = (recursiveSearch->isChecked()) ? -1 : 0; + + FileSearch* search = new FileSearch(this, fileEdit->text(), m_strLastDirSearched, recurse, caseInsensitiveCheck->isChecked()); + Q_CHECK_PTR(search); - connect(search, SIGNAL(searchComplete(const QStringList&, const QString&)), SLOT(SearchPicFinished(const QStringList&, const QString&))); - connect(search, SIGNAL(aborted(bool)), SLOT(SearchPicAborted(bool))); + + connect(search, SIGNAL(searchComplete(const QStringList&, const QString&)), SLOT(slotSearchPicFinished(const QStringList&, const QString&))); + connect(search, SIGNAL(aborted(bool)), SLOT(slotSearchPicAborted(bool))); + // Set up the UI to let the user cancel the search, then start it setSearchButton(true, search); progressBar1->setRange(0, 0); + enableGuiWhileSearching(false); search->start(); -} + } -void PicSearchOptions::SearchPicAborted(bool userCancelled) -{ - m_userCancelled = userCancelled; +void PicSearchOptions::slotSearchPicAborted(bool userCancelled) { + + m_bCancelled = userCancelled; + const FileSearch* search = dynamic_cast<const FileSearch*>(sender()); + assert(search); + setSearchButton(false, search); - if (!userCancelled) + + enableGuiWhileSearching(true); + + if (!userCancelled) { // A running search failed - QMessageBox::warning(this, tr("Scribus - Image Search"), tr("The search failed: %1").arg(search->lastError()), - QMessageBox::Ok|QMessageBox::Default|QMessageBox::Escape, - QMessageBox::NoButton); + QMessageBox::warning(this, tr("Scribus - Image Search"), + tr("The search failed: %1").arg(search->lastError()), + QMessageBox::Ok | QMessageBox::Default | QMessageBox::Escape, + QMessageBox::NoButton); + } + reject(); -} + } -void PicSearchOptions::SearchPicFinished(const QStringList & matches, const QString & fileName) -{ - m_matches = matches; - m_fileName = fileEdit->text(); +void PicSearchOptions::slotSearchPicFinished(const QStringList & matches, const QString & fileName) { + + enableGuiWhileSearching(true); + + m_listMatches = matches; + m_strFileName = fileEdit->text(); + accept(); -} + } + +void PicSearchOptions::enableGuiWhileSearching(bool enable) { + fileEdit->setEnabled(enable); + directoryEdit->setEnabled(enable); + changeDirButton->setEnabled(enable); + caseInsensitiveCheck->setEnabled(enable); + recursiveSearch->setEnabled(enable); + } + Index: picsearchoptions.h =================================================================== --- picsearchoptions.h (revision 11652) +++ picsearchoptions.h (working copy) @@ -12,6 +12,10 @@ class FileSearch; +/** + * \brief Search for matching image filenames. + */ + class SCRIBUS_API PicSearchOptions : public QDialog, Ui::PicSearchOptions { Q_OBJECT @@ -19,24 +23,58 @@ public: PicSearchOptions(QWidget* parent, const QString & fileName,const QString & searchBase); ~PicSearchOptions() {}; - QString dirToSearch; - QString m_fileName; - QStringList m_matches; - bool m_userCancelled; + + /** + * \brief Fetch the last used searchBase. + * @return Path string. + */ + const QString &getLastDirSearched () { return m_strLastDirSearched; } + /** + * \brief Fetch the filename used for the last search. + * @return Filename string. + */ + const QString &getFileName () { return m_strFileName; } + + /** + * \brief Fetch all found matches. + * @return List of file paths. + */ + const QStringList &getMatches () { return m_listMatches; } + + /** + * \brief Did the user cancel the search? + * @return <code>bool</code> TRUE if cancelled. + */ + bool getCancelled () { return m_bCancelled; } + private slots: - void changeSearchDir(); - void SearchPic(); - void SearchPicAborted(bool userCancelled); - void SearchPicFinished(const QStringList & matches, const QString & fileName); + void slotChangeSearchDir(); + void slotSearchPic(); + void slotSearchPicAborted(bool userCancelled); + void slotSearchPicFinished(const QStringList & matches, const QString & fileName); +private: + QString m_strFileName; + QString m_strLastDirSearched; + QStringList m_listMatches; + bool m_bCancelled; protected: - /*! \brief Toggle a search button in the table between "Search" and "Cancel Search", - fixing signal connections as well. - \param toCancel true in the "cancelation" state/process - \param searcher a reference to the searcher object */ + /** + * \brief Toggle a search button in the table between "Search" and "Cancel Search", + * fixing signal connections as well. + * \param toCancel true in the "cancelation" state/process + * \param searcher a reference to the searcher object + */ void setSearchButton(bool toCancel, const FileSearch* searcher); + + /** + * \brief Enable/disable gui elements while searching. + * @param enable Set to FALSE if searching. + */ + void enableGuiWhileSearching (bool enable); + }; #endif Index: picsearchoptions.ui =================================================================== --- picsearchoptions.ui (revision 11652) +++ picsearchoptions.ui (working copy) @@ -5,20 +5,32 @@ <rect> <x>0</x> <y>0</y> - <width>486</width> - <height>143</height> + <width>513</width> + <height>139</height> </rect> </property> <property name="windowTitle" > <string>Search Images</string> </property> <layout class="QGridLayout" > - <property name="margin" > + <property name="leftMargin" > <number>9</number> </property> - <property name="spacing" > + <property name="topMargin" > + <number>9</number> + </property> + <property name="rightMargin" > + <number>9</number> + </property> + <property name="bottomMargin" > + <number>9</number> + </property> + <property name="horizontalSpacing" > <number>6</number> </property> + <property name="verticalSpacing" > + <number>6</number> + </property> <item row="0" column="0" > <widget class="QLabel" name="textLabel1_2" > <property name="text" > @@ -27,6 +39,9 @@ <property name="wordWrap" > <bool>false</bool> </property> + <property name="buddy" > + <cstring>fileEdit</cstring> + </property> </widget> </item> <item row="1" column="0" > @@ -37,6 +52,9 @@ <property name="wordWrap" > <bool>false</bool> </property> + <property name="buddy" > + <cstring>directoryEdit</cstring> + </property> </widget> </item> <item row="1" column="1" > @@ -61,12 +79,21 @@ </item> <item row="3" column="0" colspan="3" > <layout class="QHBoxLayout" > - <property name="margin" > - <number>0</number> - </property> <property name="spacing" > <number>5</number> </property> + <property name="leftMargin" > + <number>0</number> + </property> + <property name="topMargin" > + <number>0</number> + </property> + <property name="rightMargin" > + <number>0</number> + </property> + <property name="bottomMargin" > + <number>0</number> + </property> <item> <widget class="QLabel" name="searchLabel" > <property name="text" > @@ -123,12 +150,21 @@ </item> <item row="2" column="0" colspan="3" > <layout class="QHBoxLayout" > - <property name="margin" > - <number>0</number> - </property> <property name="spacing" > <number>5</number> </property> + <property name="leftMargin" > + <number>0</number> + </property> + <property name="topMargin" > + <number>0</number> + </property> + <property name="rightMargin" > + <number>0</number> + </property> + <property name="bottomMargin" > + <number>0</number> + </property> <item> <widget class="QCheckBox" name="caseInsensitiveCheck" > <property name="text" > Index: picstatus.cpp =================================================================== --- picstatus.cpp (revision 11652) +++ picstatus.cpp (working copy) @@ -49,6 +49,7 @@ #include "util_formats.h" #include "util_icon.h" +#include <QDebug> PicItem::PicItem(QListWidget* parent, QString text, QPixmap pix, PageItem* pgItem) : QListWidgetItem(pix, text, parent) @@ -391,18 +392,32 @@ if (currItem == NULL) return; - PicSearchOptions *dia = new PicSearchOptions(this, displayName->text(), displayPath->text()); +static QString lastSearchPath; + + if (lastSearchPath.isEmpty()) { + qDebug() << "PicStatus: set lastsearchpath"; + lastSearchPath = displayPath->text(); + } + + qDebug() << "PicStatus: last search path = " << lastSearchPath; + + PicSearchOptions *dia = new PicSearchOptions(this, displayName->text(), lastSearchPath); if (dia->exec()) { - if (dia->m_matches.count() == 0) + + lastSearchPath = dia->getLastDirSearched(); + + qDebug() << "PicStatus: last search path set to " << lastSearchPath; + + if (dia->getMatches().count() == 0) { - QMessageBox::information(this, tr("Scribus - Image Search"), tr("No images named \"%1\" were found.").arg(dia->m_fileName), + QMessageBox::information(this, tr("Scribus - Image Search"), tr("No images named \"%1\" were found.").arg(dia->getFileName()), QMessageBox::Ok|QMessageBox::Default|QMessageBox::Escape, QMessageBox::NoButton); } else { - PicSearch *dia2 = new PicSearch(this, dia->m_fileName, dia->m_matches); + PicSearch *dia2 = new PicSearch(this, dia->getFileName(), dia->getMatches()); if (dia2->exec()) { Q_ASSERT(!dia2->currentImage.isEmpty()); |
Date Modified | Username | Field | Change |
---|---|---|---|
2008-02-14 23:20 | arvee | New Issue | |
2008-02-14 23:20 | arvee | File Added: arvee-2008-02-14.diff | |
2008-02-15 00:20 | christoph_s | Status | new => assigned |
2008-02-15 00:20 | christoph_s | Assigned To | => jghali |
2008-02-15 01:54 | christoph_s | Assigned To | jghali => fschmid |
2008-02-15 01:54 | christoph_s | Target Version | => 1.3.5 |
2008-02-15 01:54 | christoph_s | Summary | Extras / Manage Images => Enhancements to Extras > Manage Images |
2008-02-15 20:38 | fschmid | Status | assigned => resolved |
2008-02-15 20:38 | fschmid | Fixed in Version | => 1.3.5svn |
2008-02-15 20:38 | fschmid | Resolution | open => fixed |
2008-02-15 23:00 | cbradney | Status | resolved => closed |