From e859f6a71ca566f437146c293277e59e91111fb1 Mon Sep 17 00:00:00 2001 From: dockes Date: Wed, 14 Dec 2005 16:15:39 +0000 Subject: [PATCH] user interface preferences settable from ui --- src/qtgui/main.cpp | 36 +++++++++++++++++---- src/qtgui/recoll.h | 9 ++++-- src/qtgui/recoll.pro | 4 +-- src/qtgui/recollmain.ui | 26 ++++++++++++++- src/qtgui/recollmain.ui.h | 67 ++++++++++++++++++++++++++++++++------- 5 files changed, 119 insertions(+), 23 deletions(-) diff --git a/src/qtgui/main.cpp b/src/qtgui/main.cpp index d528b0f6..567e6aea 100644 --- a/src/qtgui/main.cpp +++ b/src/qtgui/main.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: main.cpp,v 1.23 2005-12-13 17:20:46 dockes Exp $ (C) 2005 J.F.Dockes"; +static char rcsid[] = "@(#$Id: main.cpp,v 1.24 2005-12-14 16:15:39 dockes Exp $ (C) 2005 J.F.Dockes"; #endif #include @@ -35,10 +35,17 @@ RclConfig *rclconfig; Rcl::Db *rcldb; int recollNeedsExit; string tmpdir; -bool showicons; string iconsdir; RclDHistory *history; +///////////////////////// +// Global variables for user preferences. These are set in the user preference +// dialog and saved restored to the appropriate place in the qt settings +bool prefs_showicons; +int prefs_respagesize = 8; +QString prefs_reslistfontfamily; +int prefs_reslistfontsize; + static string dbdir; void getQueryStemming(bool &dostem, std::string &stemlang) @@ -79,6 +86,14 @@ void recollCleanup() settings.writeEntry("/Recoll/geometry/height", height); settings.writeEntry("/Recoll/prefs/simpleSearchAll", mainWindow->allTermsCB->isChecked()); + settings.writeEntry("/Recoll/prefs/reslist/showicons", + prefs_showicons); + settings.writeEntry("/Recoll/prefs/reslist/pagelen", + prefs_respagesize); + settings.writeEntry("/Recoll/prefs/reslist/fontFamily", + prefs_reslistfontfamily); + settings.writeEntry("/Recoll/prefs/reslist/fontSize", + prefs_reslistfontsize);; } stop_idxthread(); @@ -115,10 +130,19 @@ int main( int argc, char ** argv ) // Restore some settings from previous session QSettings settings; settings.setPath("Recoll.org", "Recoll"); - int width = settings.readNumEntry( "/Recoll/geometry/width", 590); - int height = settings.readNumEntry( "/Recoll/geometry/height", 810); - bool ssall = settings.readBoolEntry( "/Recoll/prefs/simpleSearchAll", 0); + int width = settings.readNumEntry("/Recoll/geometry/width", 590); + int height = settings.readNumEntry("/Recoll/geometry/height", 810); + bool ssall = settings.readBoolEntry("/Recoll/prefs/simpleSearchAll", 0); QSize s(width, height); + prefs_showicons = + settings.readBoolEntry("/Recoll/prefs/reslist/showicons", true); + prefs_respagesize = + settings.readNumEntry("/Recoll/prefs/reslist/pagelen", 8); + prefs_reslistfontfamily = + settings.readEntry("/Recoll/prefs/reslist/fontFamily", ""); + prefs_reslistfontsize = + settings.readNumEntry("/Recoll/prefs/reslist/fontSize", 0);; + // Create main window and set its size to previous session's RecollMain w; @@ -152,8 +176,6 @@ int main( int argc, char ** argv ) translatdir.c_str() ); a.installTranslator( &translator ); - showicons = false; - rclconfig->getConfParam("showicons", &showicons); rclconfig->getConfParam("iconsdir", iconsdir); if (iconsdir.empty()) { iconsdir = path_cat(recollsharedir, "images"); diff --git a/src/qtgui/recoll.h b/src/qtgui/recoll.h index e196ee6f..79879cb7 100644 --- a/src/qtgui/recoll.h +++ b/src/qtgui/recoll.h @@ -1,6 +1,6 @@ #ifndef _RECOLL_H_INCLUDED_ #define _RECOLL_H_INCLUDED_ -/* @(#$Id: recoll.h,v 1.7 2005-11-28 15:31:01 dockes Exp $ (C) 2004 J.F.Dockes */ +/* @(#$Id: recoll.h,v 1.8 2005-12-14 16:15:39 dockes Exp $ (C) 2004 J.F.Dockes */ #include #include @@ -18,10 +18,15 @@ extern bool maybeOpenDb(std::string &reason); extern RclConfig *rclconfig; extern Rcl::Db *rcldb; extern std::string tmpdir; -extern bool showicons; extern string iconsdir; extern RclDHistory *history; extern int recollNeedsExit; +class QString; +extern bool prefs_showicons; +extern int prefs_respagesize; +extern QString prefs_reslistfontfamily; +extern int prefs_reslistfontsize; + #endif /* _RECOLL_H_INCLUDED_ */ diff --git a/src/qtgui/recoll.pro b/src/qtgui/recoll.pro index a43fff52..efba4431 100644 --- a/src/qtgui/recoll.pro +++ b/src/qtgui/recoll.pro @@ -10,7 +10,8 @@ SOURCES += main.cpp \ FORMS = recollmain.ui \ advsearch.ui \ preview/preview.ui \ - sort.ui + sort.ui \ + uiprefs.ui IMAGES = images/filenew \ images/fileopen \ @@ -36,7 +37,6 @@ unix { $(BSTATIC) $(LIBXAPIAN) $(LIBICONV) $(BDYNAMIC) \ -lz INCLUDEPATH += ../common ../index ../query ../unac ../utils - } UNAME = $$system(uname -s) diff --git a/src/qtgui/recollmain.ui b/src/qtgui/recollmain.ui index ff5c5899..ff3ae9b0 100644 --- a/src/qtgui/recollmain.ui +++ b/src/qtgui/recollmain.ui @@ -168,6 +168,9 @@ + + + @@ -324,6 +327,17 @@ Previous page of results + + + preferencesUser_InterfaceAction + + + &User Interface + + + &User Interface + + @@ -410,6 +424,12 @@ RecollMain showResultPage() + + preferencesUser_InterfaceAction + activated() + RecollMain + showUIPrefs() + sortseq.h @@ -417,6 +437,7 @@ recoll.h advsearch.h sort.h + uiprefs.h recollmain.ui.h @@ -432,6 +453,7 @@ Preview *curPreview; advsearch *asearchform; SortForm *sortform; + UIPrefsDialog *uiprefs; int sortwidth; RclSortSpec sortspecs; DocSequence *docsource; @@ -457,12 +479,14 @@ showDocHistory() searchTextChanged( const QString & text ) sortDataChanged( int cnt, RclSortSpec spec ) + showUIPrefs() + setUIPrefs() init() close( bool ) eventFilter( QObject * target, QEvent * event ) - reldocnumfromparnum( int parnum ) + reldocnumfromparnum( int par ) startPreview( int docnum ) startNativeViewer( int docnum ) diff --git a/src/qtgui/recollmain.ui.h b/src/qtgui/recollmain.ui.h index b91744fa..f1873337 100644 --- a/src/qtgui/recollmain.ui.h +++ b/src/qtgui/recollmain.ui.h @@ -30,6 +30,8 @@ using std::pair; #include #include #include +#include +#include #include "recoll.h" #include "debuglog.h" @@ -40,6 +42,7 @@ using std::pair; #include "advsearch.h" #include "rclversion.h" #include "sortseq.h" +#include "uiprefs.h" extern "C" int XFlush(void *); @@ -47,10 +50,6 @@ extern "C" int XFlush(void *); #define MIN(A,B) ((A) < (B) ? (A) : (B)) #endif -// Number of abstracts in a result page. This will avoid scrollbars -// with the default window size and font, most of the time. -static const int respagesize = 8; - void RecollMain::init() { reslist_winfirst = -1; @@ -66,6 +65,7 @@ void RecollMain::init() sortform = 0; docsource = 0; sortwidth = 0; + uiprefs = 0; // We manage pgup/down, but let ie the arrows for the editor to process reslistTE->installEventFilter(this); @@ -74,6 +74,12 @@ void RecollMain::init() // Set the focus to the search terms entry: queryText->setFocus(); + + // Set result list font according to user preferences. + if (prefs_reslistfontfamily.length()) { + QFont nfont(prefs_reslistfontfamily, prefs_reslistfontsize); + reslistTE->setFont(nfont); + } } // We also want to get rid of the advanced search form and previews @@ -419,7 +425,7 @@ void RecollMain::resultPageBack() { if (reslist_winfirst <= 0) return; - reslist_winfirst -= 2*respagesize; + reslist_winfirst -= 2 * prefs_respagesize; showResultPage(); } @@ -441,7 +447,8 @@ void RecollMain::showResultPage() pageParaToReldocnums.clear(); // If we are already on the last page, nothing to do: - if (reslist_winfirst >= 0 && (reslist_winfirst + respagesize > resCnt)) { + if (reslist_winfirst >= 0 && + (reslist_winfirst + prefs_respagesize > resCnt)) { nextPageAction->setEnabled(false); return; } @@ -451,13 +458,13 @@ void RecollMain::showResultPage() prevPageAction->setEnabled(false); } else { prevPageAction->setEnabled(true); - reslist_winfirst += respagesize; + reslist_winfirst += prefs_respagesize; } bool gotone = false; reslistTE->clear(); - int last = MIN(resCnt-reslist_winfirst, respagesize); + int last = MIN(resCnt-reslist_winfirst, prefs_respagesize); // Insert results if any in result list window. We have to send @@ -509,7 +516,7 @@ void RecollMain::showResultPage() result = "

"; string img_name; - if (showicons) { + if (prefs_showicons) { string iconname = rclconfig->getMimeIconName(doc.mimetype); if (iconname.empty()) iconname = "document"; @@ -565,7 +572,7 @@ void RecollMain::showResultPage() /*""*/ "No results found" "
")); - reslist_winfirst -= respagesize; + reslist_winfirst -= prefs_respagesize; if (reslist_winfirst < 0) reslist_winfirst = -1; } @@ -584,7 +591,7 @@ void RecollMain::showResultPage() } #endif - if (reslist_winfirst >= 0 && (reslist_winfirst + respagesize >= resCnt)) { + if (reslist_winfirst >= 0 && (reslist_winfirst + prefs_respagesize >= resCnt)) { nextPageAction->setEnabled(false); } else { nextPageAction->setEnabled(true); @@ -641,6 +648,22 @@ void RecollMain::showSortDialog() } +void RecollMain::showUIPrefs() +{ + if (uiprefs == 0) { + uiprefs = new UIPrefsDialog(0, tr("User interface preferences"), FALSE, + WStyle_Customize | WStyle_NormalBorder | + WStyle_Title | WStyle_SysMenu); + uiprefs->setSizeGripEnabled(FALSE); + connect(uiprefs, SIGNAL(uiprefsDone()), this, SLOT(setUIPrefs())); + uiprefs->show(); + } else { + // Close and reopen, in hope that makes us visible... + uiprefs->close(); + uiprefs->show(); + } +} + /** * Open a preview window for a given document, or load it into new tab of * existing window. @@ -790,3 +813,25 @@ void RecollMain::sortDataChanged(int cnt, RclSortSpec spec) sortwidth = cnt; sortspecs = spec; } + +// This could be handled inside the dialog's accept(), but we may want to +// do something (ie: redisplay reslist?) +void RecollMain::setUIPrefs() +{ + if (!uiprefs) + return; + LOGDEB(("Recollmain::setUIPrefs\n")); + prefs_showicons = uiprefs->useIconsCB->isChecked(); + prefs_respagesize = uiprefs->pageLenSB->value(); + prefs_reslistfontfamily = uiprefs->reslistFontFamily; + prefs_reslistfontsize = uiprefs->reslistFontSize; + + if (prefs_reslistfontfamily.length()) { + QFont nfont(prefs_reslistfontfamily, prefs_reslistfontsize); + reslistTE->setFont(nfont); + } else { + reslistTE->setFont(this->font()); + } +} + +