small cleanups in gui modules couplings

This commit is contained in:
Jean-Francois Dockes 2010-12-17 16:32:41 +01:00
parent 61348a7731
commit 23222e752e
6 changed files with 90 additions and 102 deletions

View File

@ -108,12 +108,6 @@ void RclMain::init()
// Set the focus to the search terms entry: // Set the focus to the search terms entry:
sSearch->queryText->setFocus(); sSearch->queryText->setFocus();
// Set result list font according to user preferences.
if (prefs.reslistfontfamily.length()) {
QFont nfont(prefs.reslistfontfamily, prefs.reslistfontsize);
resList->setFont(nfont);
}
// Stemming language menu // Stemming language menu
g_stringNoStem = tr("(no stemming)"); g_stringNoStem = tr("(no stemming)");
g_stringAllStem = tr("(all languages)"); g_stringAllStem = tr("(all languages)");
@ -152,7 +146,6 @@ void RclMain::init()
QShortcut *sc = new QShortcut(seq, this); QShortcut *sc = new QShortcut(seq, this);
connect(sc, SIGNAL (activated()), this, SLOT (focusToSearch())); connect(sc, SIGNAL (activated()), this, SLOT (focusToSearch()));
// Toolbar+combobox version of the category selector // Toolbar+combobox version of the category selector
QComboBox *catgCMB = 0; QComboBox *catgCMB = 0;
if (prefs.catgToolBar) { if (prefs.catgToolBar) {
@ -173,7 +166,6 @@ void RclMain::init()
int bgrpid = 0; int bgrpid = 0;
bgrp->addButton(allRDB, bgrpid++); bgrp->addButton(allRDB, bgrpid++);
connect(bgrp, SIGNAL(buttonClicked(int)), this, SLOT(catgFilter(int))); connect(bgrp, SIGNAL(buttonClicked(int)), this, SLOT(catgFilter(int)));
allRDB->setChecked(true); allRDB->setChecked(true);
list<string> cats; list<string> cats;
rclconfig->getMimeCategories(cats); rclconfig->getMimeCategories(cats);
@ -195,9 +187,10 @@ void RclMain::init()
if (prefs.catgToolBar) if (prefs.catgToolBar)
catgBGRP->hide(); catgBGRP->hide();
// Connections // Connections
connect(sSearch, SIGNAL(startSearch(RefCntr<Rcl::SearchData>)), connect(sSearch, SIGNAL(startSearch(RefCntr<Rcl::SearchData>)),
this, SLOT(startSearch(RefCntr<Rcl::SearchData>))); this, SLOT(startSearch(RefCntr<Rcl::SearchData>)));
sSearch->queryText->installEventFilter(this); sSearch->queryText->installEventFilter(this);
connect(preferencesMenu, SIGNAL(triggered(QAction*)), connect(preferencesMenu, SIGNAL(triggered(QAction*)),
@ -213,22 +206,23 @@ void RclMain::init()
connect(nextPageAction, SIGNAL(activated()), connect(nextPageAction, SIGNAL(activated()),
resList, SLOT(resPageDownOrNext())); resList, SLOT(resPageDownOrNext()));
connect(resList, SIGNAL(docExpand(int)), this, SLOT(docExpand(int))); connect(resList, SIGNAL(docExpand(Rcl::Doc)),
this, SLOT(docExpand(Rcl::Doc)));
connect(resList, SIGNAL(wordSelect(QString)), connect(resList, SIGNAL(wordSelect(QString)),
this, SLOT(ssearchAddTerm(QString))); sSearch, SLOT(addTerm(QString)));
connect(resList, SIGNAL(nextPageAvailable(bool)), connect(resList, SIGNAL(nextPageAvailable(bool)),
this, SLOT(enableNextPage(bool))); this, SLOT(enableNextPage(bool)));
connect(resList, SIGNAL(prevPageAvailable(bool)), connect(resList, SIGNAL(prevPageAvailable(bool)),
this, SLOT(enablePrevPage(bool))); this, SLOT(enablePrevPage(bool)));
connect(resList, SIGNAL(docEditClicked(int)), connect(resList, SIGNAL(docEditClicked(Rcl::Doc)),
this, SLOT(startNativeViewer(int))); this, SLOT(startNativeViewer(Rcl::Doc)));
connect(resList, SIGNAL(docSaveToFileClicked(int)), connect(resList, SIGNAL(docSaveToFileClicked(Rcl::Doc)),
this, SLOT(saveDocToFile(int))); this, SLOT(saveDocToFile(Rcl::Doc)));
connect(resList, SIGNAL(editRequested(Rcl::Doc)), connect(resList, SIGNAL(editRequested(Rcl::Doc)),
this, SLOT(startNativeViewer(Rcl::Doc))); this, SLOT(startNativeViewer(Rcl::Doc)));
connect(resList, SIGNAL(docPreviewClicked(int, int)), connect(resList, SIGNAL(docPreviewClicked(int, Rcl::Doc, int)),
this, SLOT(startPreview(int, int))); this, SLOT(startPreview(int, Rcl::Doc, int)));
connect(resList, SIGNAL(previewRequested(Rcl::Doc)), connect(resList, SIGNAL(previewRequested(Rcl::Doc)),
this, SLOT(startPreview(Rcl::Doc))); this, SLOT(startPreview(Rcl::Doc)));
@ -248,8 +242,8 @@ void RclMain::init()
this, SLOT(showAdvSearchDialog())); this, SLOT(showAdvSearchDialog()));
connect(toolsSpellAction, SIGNAL(activated()), connect(toolsSpellAction, SIGNAL(activated()),
this, SLOT(showSpellDialog())); this, SLOT(showSpellDialog()));
connect(indexConfigAction, SIGNAL(activated()),
connect(indexConfigAction, SIGNAL(activated()), this, SLOT(showIndexConfig())); this, SLOT(showIndexConfig()));
connect(queryPrefsAction, SIGNAL(activated()), this, SLOT(showUIPrefs())); connect(queryPrefsAction, SIGNAL(activated()), this, SLOT(showUIPrefs()));
connect(extIdxAction, SIGNAL(activated()), this, SLOT(showExtIdxDialog())); connect(extIdxAction, SIGNAL(activated()), this, SLOT(showExtIdxDialog()));
if (prefs.catgToolBar && catgCMB) if (prefs.catgToolBar && catgCMB)
@ -591,7 +585,7 @@ void RclMain::showSpellDialog()
if (spellform == 0) { if (spellform == 0) {
spellform = new SpellW(0); spellform = new SpellW(0);
connect(spellform, SIGNAL(wordSelect(QString)), connect(spellform, SIGNAL(wordSelect(QString)),
this, SLOT(ssearchAddTerm(QString))); sSearch, SLOT(addTerm(QString)));
spellform->show(); spellform->show();
} else { } else {
// Close and reopen, in hope that makes us visible... // Close and reopen, in hope that makes us visible...
@ -683,15 +677,9 @@ void RclMain::previewClosed(Preview *w)
* @param docnum db query index * @param docnum db query index
* @param mod keyboards modifiers like ControlButton, ShiftButton * @param mod keyboards modifiers like ControlButton, ShiftButton
*/ */
void RclMain::startPreview(int docnum, int mod) void RclMain::startPreview(int docnum, Rcl::Doc doc, int mod)
{ {
Rcl::Doc doc; LOGDEB(("startPreview(%d, doc, %d)\n", docnum, mod));
if (!resList->getDoc(docnum, doc)) {
QMessageBox::warning(0, "Recoll", tr("Cannot retrieve document info"
" from database"));
return;
}
if (mod & Qt::ShiftModifier) { if (mod & Qt::ShiftModifier) {
// User wants new preview window // User wants new preview window
curPreview = 0; curPreview = 0;
@ -710,7 +698,7 @@ void RclMain::startPreview(int docnum, int mod)
connect(curPreview, SIGNAL(previewClosed(Preview *)), connect(curPreview, SIGNAL(previewClosed(Preview *)),
this, SLOT(previewClosed(Preview *))); this, SLOT(previewClosed(Preview *)));
connect(curPreview, SIGNAL(wordSelect(QString)), connect(curPreview, SIGNAL(wordSelect(QString)),
this, SLOT(ssearchAddTerm(QString))); sSearch, SLOT(addTerm(QString)));
connect(curPreview, SIGNAL(showNext(Preview *, int, int)), connect(curPreview, SIGNAL(showNext(Preview *, int, int)),
this, SLOT(previewNextInTab(Preview *, int, int))); this, SLOT(previewNextInTab(Preview *, int, int)));
connect(curPreview, SIGNAL(showPrev(Preview *, int, int)), connect(curPreview, SIGNAL(showPrev(Preview *, int, int)),
@ -741,7 +729,7 @@ void RclMain::startPreview(Rcl::Doc doc)
return; return;
} }
connect(preview, SIGNAL(wordSelect(QString)), connect(preview, SIGNAL(wordSelect(QString)),
this, SLOT(ssearchAddTerm(QString))); sSearch, SLOT(addTerm(QString)));
preview->show(); preview->show();
preview->makeDocCurrent(doc, 0); preview->makeDocCurrent(doc, 0);
} }
@ -851,43 +839,8 @@ void RclMain::on_actionSortByDateDesc_toggled(bool on)
onSortDataChanged(); onSortDataChanged();
} }
// Add term to simple search. Term comes out of double-click in void RclMain::saveDocToFile(Rcl::Doc doc)
// reslist or preview.
// It would probably be better to cleanup in preview.ui.h and
// reslist.cpp and do the proper html stuff in the latter case
// (which is different because it format is explicit richtext
// instead of auto as for preview, needed because it's built by
// fragments?).
static const char* punct = " \t()<>\"'[]{}!^*.,:;\n\r";
void RclMain::ssearchAddTerm(QString term)
{ {
LOGDEB(("RclMain::ssearchAddTerm: [%s]\n", (const char *)term.toUtf8()));
string t = (const char *)term.toUtf8();
string::size_type pos = t.find_last_not_of(punct);
if (pos == string::npos)
return;
t = t.substr(0, pos+1);
pos = t.find_first_not_of(punct);
if (pos != string::npos)
t = t.substr(pos);
if (t.empty())
return;
term = QString::fromUtf8(t.c_str());
QString text = sSearch->queryText->currentText();
text += QString::fromLatin1(" ") + term;
sSearch->queryText->setEditText(text);
}
void RclMain::saveDocToFile(int docnum)
{
Rcl::Doc doc;
if (!resList->getDoc(docnum, doc)) {
QMessageBox::warning(0, "Recoll",
tr("Cannot retrieve document info"
" from database"));
return;
}
QString s = QString s =
QFileDialog::getSaveFileName(this, //parent QFileDialog::getSaveFileName(this, //parent
tr("Save file"), // caption tr("Save file"), // caption
@ -926,17 +879,6 @@ static bool lookForHtmlBrowser(string &exefile)
return false; return false;
} }
void RclMain::startNativeViewer(int docnum)
{
Rcl::Doc doc;
if (!resList->getDoc(docnum, doc)) {
QMessageBox::warning(0, "Recoll", tr("Cannot retrieve document info"
" from database"));
return;
}
startNativeViewer(doc);
}
// Convert to file path if url is like file:// // Convert to file path if url is like file://
static string fileurltolocalpath(string url) static string fileurltolocalpath(string url)
{ {
@ -1171,13 +1113,10 @@ void RclMain::startManual(const string& index)
// Search for document 'like' the selected one. We ask rcldb/xapian to find // Search for document 'like' the selected one. We ask rcldb/xapian to find
// significant terms, and add them to the simple search entry. // significant terms, and add them to the simple search entry.
void RclMain::docExpand(int docnum) void RclMain::docExpand(Rcl::Doc doc)
{ {
if (!rcldb) if (!rcldb)
return; return;
Rcl::Doc doc;
if (!resList->getDoc(docnum, doc))
return;
list<string> terms; list<string> terms;
terms = resList->expand(doc); terms = resList->expand(doc);
if (terms.empty()) if (terms.empty())

View File

@ -75,13 +75,11 @@ public slots:
virtual void setUIPrefs(); virtual void setUIPrefs();
virtual void enableNextPage(bool); virtual void enableNextPage(bool);
virtual void enablePrevPage(bool); virtual void enablePrevPage(bool);
virtual void docExpand(int); virtual void docExpand(Rcl::Doc);
virtual void ssearchAddTerm(QString); virtual void startPreview(int doc, Rcl::Doc doc, int keymods);
virtual void startPreview(int docnum, int); virtual void startPreview(Rcl::Doc);
virtual void startPreview(Rcl::Doc doc); virtual void startNativeViewer(Rcl::Doc);
virtual void startNativeViewer(int docnum); virtual void saveDocToFile(Rcl::Doc);
virtual void startNativeViewer(Rcl::Doc doc);
virtual void saveDocToFile(int docnum);
virtual void previewNextInTab(Preview *, int sid, int docnum); virtual void previewNextInTab(Preview *, int sid, int docnum);
virtual void previewPrevInTab(Preview *, int sid, int docnum); virtual void previewPrevInTab(Preview *, int sid, int docnum);
virtual void previewExposed(Preview *, int sid, int docnum); virtual void previewExposed(Preview *, int sid, int docnum);

View File

@ -233,6 +233,10 @@ ResList::ResList(QWidget* parent, const char* name)
m_listId = 0; m_listId = 0;
m_pager = new QtGuiResListPager(this, prefs.respagesize); m_pager = new QtGuiResListPager(this, prefs.respagesize);
m_pager->setHighLighter(&g_hiliter); m_pager->setHighLighter(&g_hiliter);
if (prefs.reslistfontfamily.length()) {
QFont nfont(prefs.reslistfontfamily, prefs.reslistfontsize);
setFont(nfont);
}
} }
ResList::~ResList() ResList::~ResList()
@ -625,6 +629,7 @@ void ResList::linkWasClicked(const QUrl &url)
QString s = url.toString(); QString s = url.toString();
const char *ascurl = s.toAscii(); const char *ascurl = s.toAscii();
LOGDEB(("ResList::linkWasClicked: [%s]\n", ascurl)); LOGDEB(("ResList::linkWasClicked: [%s]\n", ascurl));
int i = atoi(ascurl+1) - 1; int i = atoi(ascurl+1) - 1;
int what = ascurl[0]; int what = ascurl[0];
switch (what) { switch (what) {
@ -632,18 +637,28 @@ void ResList::linkWasClicked(const QUrl &url)
emit headerClicked(); emit headerClicked();
break; break;
case 'P': case 'P':
emit docPreviewClicked(i, m_lstClckMod);
break;
case 'E': case 'E':
emit docEditClicked(i); {
break; Rcl::Doc doc;
if (!getDoc(i, doc)) {
LOGERR(("ResList::linkWasClicked: can't get doc for %d\n", i));
return;
}
if (what == 'P')
emit docPreviewClicked(i, doc, m_lstClckMod);
else
emit docEditClicked(doc);
}
break;
case 'n': case 'n':
resultPageNext(); resultPageNext();
break; break;
case 'p': case 'p':
resultPageBack(); resultPageBack();
break; break;
default: break;// ?? default:
LOGERR(("ResList::linkWasClicked: bad link [%s]\n", ascurl));
break;// ??
} }
} }
@ -677,11 +692,15 @@ void ResList::createPopupMenu(const QPoint& pos)
void ResList::menuPreview() void ResList::menuPreview()
{ {
emit docPreviewClicked(m_popDoc, 0); Rcl::Doc doc;
if (getDoc(m_popDoc, doc))
emit docPreviewClicked(m_popDoc, doc, 0);
} }
void ResList::menuSaveToFile() void ResList::menuSaveToFile()
{ {
emit docSaveToFileClicked(m_popDoc); Rcl::Doc doc;
if (getDoc(m_popDoc, doc))
emit docSaveToFileClicked(doc);
} }
void ResList::menuPreviewParent() void ResList::menuPreviewParent()
@ -720,7 +739,9 @@ void ResList::menuOpenParent()
void ResList::menuEdit() void ResList::menuEdit()
{ {
emit docEditClicked(m_popDoc); Rcl::Doc doc;
if (getDoc(m_popDoc, doc))
emit docEditClicked(doc);
} }
void ResList::menuCopyFN() void ResList::menuCopyFN()
{ {
@ -755,7 +776,9 @@ void ResList::menuCopyURL()
void ResList::menuExpand() void ResList::menuExpand()
{ {
emit docExpand(m_popDoc); Rcl::Doc doc;
if (getDoc(m_popDoc, doc))
emit docExpand(doc);
} }
QString ResList::getDescription() QString ResList::getDescription()

View File

@ -82,13 +82,13 @@ class ResList : public QTextBrowser
signals: signals:
void nextPageAvailable(bool); void nextPageAvailable(bool);
void prevPageAvailable(bool); void prevPageAvailable(bool);
void docEditClicked(int); void docEditClicked(Rcl::Doc);
void docPreviewClicked(int, int); void docPreviewClicked(int, Rcl::Doc, int);
void docSaveToFileClicked(int); void docSaveToFileClicked(Rcl::Doc);
void previewRequested(Rcl::Doc); void previewRequested(Rcl::Doc);
void editRequested(Rcl::Doc); void editRequested(Rcl::Doc);
void headerClicked(); void headerClicked();
void docExpand(int); void docExpand(Rcl::Doc);
void wordSelect(QString); void wordSelect(QString);
void linkClicked(const QString&, int); // See emitLinkClicked() void linkClicked(const QString&, int); // See emitLinkClicked()
void hasResults(int); void hasResults(int);

View File

@ -216,6 +216,34 @@ bool SSearch::hasSearchString()
return !queryText->lineEdit()->text().isEmpty(); return !queryText->lineEdit()->text().isEmpty();
} }
// Add term to simple search. Term comes out of double-click in
// reslist or preview.
// It would probably be better to cleanup in preview.ui.h and
// reslist.cpp and do the proper html stuff in the latter case
// (which is different because it format is explicit richtext
// instead of auto as for preview, needed because it's built by
// fragments?).
static const char* punct = " \t()<>\"'[]{}!^*.,:;\n\r";
void SSearch::addTerm(QString term)
{
LOGDEB(("SSearch::AddTerm: [%s]\n", (const char *)term.toUtf8()));
string t = (const char *)term.toUtf8();
string::size_type pos = t.find_last_not_of(punct);
if (pos == string::npos)
return;
t = t.substr(0, pos+1);
pos = t.find_first_not_of(punct);
if (pos != string::npos)
t = t.substr(pos);
if (t.empty())
return;
term = QString::fromUtf8(t.c_str());
QString text = queryText->currentText();
text += QString::fromLatin1(" ") + term;
queryText->setEditText(text);
}
void SSearch::setAnyTermMode() void SSearch::setAnyTermMode()
{ {
searchTypCMB->setCurrentIndex(SST_ANY); searchTypCMB->setCurrentIndex(SST_ANY);

View File

@ -46,12 +46,12 @@ public:
virtual void completion(); virtual void completion();
virtual bool eventFilter(QObject *target, QEvent *event); virtual bool eventFilter(QObject *target, QEvent *event);
virtual bool hasSearchString(); virtual bool hasSearchString();
public slots: public slots:
virtual void searchTextChanged(const QString & text); virtual void searchTextChanged(const QString & text);
virtual void searchTypeChanged(int); virtual void searchTypeChanged(int);
virtual void setSearchString(const QString& text); virtual void setSearchString(const QString& text);
virtual void startSimpleSearch(); virtual void startSimpleSearch();
virtual void addTerm(QString);
signals: signals:
void startSearch(RefCntr<Rcl::SearchData>); void startSearch(RefCntr<Rcl::SearchData>);