1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
/***************************************************************************
picsearchoptions.cpp - description
-------------------
begin : Mon Feb 26 2007
copyright : (C) 2007 by Franz Schmid
email : Franz.Schmid@altmuehlnet.de
***************************************************************************/
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
#include <cassert>
#include <QCheckBox>
#include <QDir>
#include <QFileDialog>
#include <QLabel>
#include <QLineEdit>
#include <QMessageBox>
#include <QPushButton>
#include <QStringList>
#include <QToolTip>
#include "picsearchoptions.h"
#include "filesearch.h"
PicSearchOptions::PicSearchOptions(QWidget* parent, const QString & fileName, const QString & searchBase) : QDialog( parent )
{
setupUi(this);
setModal(true);
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(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(slotSearchPic()));
connect(startButton, SIGNAL(clicked()), searcher, SLOT(cancel()));
}
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(slotSearchPic()));
}
}
void PicSearchOptions::slotChangeSearchDir()
{
QString workDir = directoryEdit->text();
#ifndef _WIN32
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 = QFileDialog::getExistingDirectory(this, tr("Select a base directory for search"), workDir);
if (searchBase.isEmpty() || !QDir().exists(searchBase))
return;
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)
return;
slotChangeSearchDir();
searchBase = directoryEdit->text();
if (searchBase.isEmpty() || !QDir().exists(searchBase))
return;
}
m_strLastDirSearched = searchBase;
// 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 = (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(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::slotSearchPicAborted(bool userCancelled)
{
m_bCancelled = userCancelled;
const FileSearch* search = dynamic_cast<const FileSearch*>(sender());
assert(search);
setSearchButton(false, search);
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);
reject();
}
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);
}
|