user interface preferences settable from ui

This commit is contained in:
dockes 2005-12-14 16:15:39 +00:00
parent be485e8059
commit e859f6a71c
5 changed files with 119 additions and 23 deletions

View File

@ -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 <unistd.h>
@ -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");

View File

@ -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 <string>
#include <list>
@ -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_ */

View File

@ -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)

View File

@ -168,6 +168,9 @@
<action name="toolsAdvanced_SearchAction"/>
<action name="toolsSort_parametersAction"/>
</item>
<item text="&amp;Preferences" name="Preferences">
<action name="preferencesUser_InterfaceAction"/>
</item>
<separator/>
<item text="&amp;Help" name="Help">
<separator/>
@ -324,6 +327,17 @@
<string>Previous page of results</string>
</property>
</action>
<action>
<property name="name">
<cstring>preferencesUser_InterfaceAction</cstring>
</property>
<property name="text">
<string>&amp;User Interface</string>
</property>
<property name="menuText">
<string>&amp;User Interface</string>
</property>
</action>
</actions>
<connections>
<connection>
@ -410,6 +424,12 @@
<receiver>RecollMain</receiver>
<slot>showResultPage()</slot>
</connection>
<connection>
<sender>preferencesUser_InterfaceAction</sender>
<signal>activated()</signal>
<receiver>RecollMain</receiver>
<slot>showUIPrefs()</slot>
</connection>
</connections>
<includes>
<include location="local" impldecl="in declaration">sortseq.h</include>
@ -417,6 +437,7 @@
<include location="local" impldecl="in declaration">recoll.h</include>
<include location="local" impldecl="in declaration">advsearch.h</include>
<include location="local" impldecl="in declaration">sort.h</include>
<include location="local" impldecl="in declaration">uiprefs.h</include>
<include location="local" impldecl="in implementation">recollmain.ui.h</include>
</includes>
<variables>
@ -432,6 +453,7 @@
<variable>Preview *curPreview;</variable>
<variable>advsearch *asearchform;</variable>
<variable>SortForm *sortform;</variable>
<variable>UIPrefsDialog *uiprefs;</variable>
<variable>int sortwidth;</variable>
<variable>RclSortSpec sortspecs;</variable>
<variable>DocSequence *docsource;</variable>
@ -457,12 +479,14 @@
<slot>showDocHistory()</slot>
<slot>searchTextChanged( const QString &amp; text )</slot>
<slot>sortDataChanged( int cnt, RclSortSpec spec )</slot>
<slot>showUIPrefs()</slot>
<slot>setUIPrefs()</slot>
</slots>
<functions>
<function access="private">init()</function>
<function returnType="bool">close( bool )</function>
<function access="private" returnType="bool">eventFilter( QObject * target, QEvent * event )</function>
<function access="private" returnType="int">reldocnumfromparnum( int parnum )</function>
<function access="private" returnType="int">reldocnumfromparnum( int par )</function>
<function access="private">startPreview( int docnum )</function>
<function access="private">startNativeViewer( int docnum )</function>
</functions>

View File

@ -30,6 +30,8 @@ using std::pair;
#include <qwindowdefs.h>
#include <qapplication.h>
#include <qcheckbox.h>
#include <qfontdialog.h>
#include <qspinbox.h>
#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 = "<p>";
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()
/*"<img align=\"left\" source=\"myimage\">"*/
"<b>No results found</b>"
"<br>"));
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());
}
}