Switch to side-by-side view

--- a/src/qtgui/main.cpp
+++ b/src/qtgui/main.cpp
@@ -1,20 +1,41 @@
 #ifndef lint
-static char rcsid[] = "@(#$Id: main.cpp,v 1.33 2006-01-22 18:46:41 dockes Exp $ (C) 2005 J.F.Dockes";
-#endif
+static char rcsid[] = "@(#$Id: main.cpp,v 1.34 2006-01-23 13:32:05 dockes Exp $ (C) 2005 J.F.Dockes";
+#endif
+/*
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the
+ *   Free Software Foundation, Inc.,
+ *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
 
 #include <unistd.h>
 
+//#define WITH_KDE
+#ifdef WITH_KDE
+#include <kapplication.h>
+#include <kmainwindow.h>
+#include <kaboutdata.h>
+#include <kcmdlineargs.h>
+#include <klocale.h>
+#else
 #include <qapplication.h>
-//#define WITH_KDE
-#ifdef WITH_KDE
-#include <kapplication.h>
-#endif
 #include <qtranslator.h>
+#endif
+
 #include <qtextcodec.h> 
 #include <qthread.h>
 #include <qtimer.h>
 #include <qmessagebox.h>
-#include <qsettings.h>
 #include <qcheckbox.h>
 
 
@@ -28,10 +49,23 @@
 #include "smallut.h"
 #include "rclinit.h"
 #include "debuglog.h"
-
+#include "rclversion.h"
 #include "rclmain.h"
-
-static const char *recoll_datadir = RECOLL_DATADIR;
+#include "guiutils.h"
+
+#ifdef WITH_KDE
+static const char description[] =
+    I18N_NOOP("A KDE fulltext search application");
+
+static KCmdLineOptions options[] =
+{
+//    { "+[URL]", I18N_NOOP( "Document to open" ), 0 },
+    KCmdLineLastOption
+};
+#endif
+
+
+const string recoll_datadir = RECOLL_DATADIR;
 
 RclConfig *rclconfig;
 Rcl::Db *rcldb;
@@ -40,52 +74,6 @@
 static RclMainBase *mainWindow;
 static string recollsharedir;
 
-///////////////////////// 
-// 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;
-QString prefs_queryStemLang;
-int prefs_mainwidth;
-int prefs_mainheight;
-bool prefs_ssall;
-QString prefs_htmlBrowser;
-
-#define SETTING_RW(var, nm, tp, def)			\
-    if (writing) {					\
-	settings.writeEntry(nm , var);			\
-    } else {						\
-	var = settings.read##tp##Entry(nm, def);	\
-    }						
-
-static void rwSettings(bool writing)
-{
-    if (writing) {
-	if (!mainWindow) 
-	    return;
-	prefs_mainwidth = mainWindow->width();
-	prefs_mainheight = mainWindow->height();
-	prefs_ssall = mainWindow->sSearch->allTermsCB->isChecked();
-    }
-
-    QSettings settings;
-    settings.setPath("Recoll.org", "Recoll");
-
-    SETTING_RW(prefs_mainwidth, "/Recoll/geometry/width", Num, 590);
-    SETTING_RW(prefs_mainheight, "/Recoll/geometry/height", Num, 810);
-    SETTING_RW(prefs_ssall, "/Recoll/prefs/simpleSearchAll", Bool, false);
-    SETTING_RW(prefs_showicons, "/Recoll/prefs/reslist/showicons", Bool, true);
-    SETTING_RW(prefs_respagesize, "/Recoll/prefs/reslist/pagelen", Num, 8);
-    SETTING_RW(prefs_reslistfontfamily, "/Recoll/prefs/reslist/fontFamily", ,
-	       "");
-    SETTING_RW(prefs_reslistfontsize, "/Recoll/prefs/reslist/fontSize", Num, 
-	       0);
-    SETTING_RW(prefs_queryStemLang, "/Recoll/prefs/query/stemLang", ,
-	       "english");
-}
-
 bool maybeOpenDb(string &reason)
 {
     if (!rcldb) {
@@ -102,6 +90,11 @@
 
 static void recollCleanup()
 {
+    if (mainWindow) {
+	prefs.mainwidth = mainWindow->width();
+	prefs.mainheight = mainWindow->height();
+	prefs.ssall = mainWindow->sSearch->allTermsCB->isChecked();
+    }
     rwSettings(true);
     stop_idxthread();
     delete rcldb;
@@ -119,19 +112,26 @@
     recollNeedsExit = 1;
 }
 
+extern void qInitImages_recoll();
 
 int main( int argc, char ** argv )
 {
 #ifdef WITH_KDE
-    KApplication a(argc, argv, "recoll");
+    KAboutData about("recoll", I18N_NOOP("Recoll"), rclversion, description,
+                     KAboutData::License_GPL, "(C) 2006 Jean-Francois Dockes", 0, 0, "jean-francois.dockes@wanadoo.fr");
+    about.addAuthor( "Jean-Francois Dockes", 0, 
+		     "jean-francois.dockes@wanadoo.fr" );
+    KCmdLineArgs::init(argc, argv, &about);
+    KCmdLineArgs::addCmdLineOptions( options );
+    KApplication app;
 #else
-    QApplication a(argc, argv);
-#endif
-
-    // translation file for Qt
+    QApplication app(argc, argv);
+#endif
+
+    // Translation file for Qt
     QTranslator qt( 0 );
     qt.load( QString( "qt_" ) + QTextCodec::locale(), "." );
-    a.installTranslator( &qt );
+    app.installTranslator( &qt );
 
     // Translations for Recoll
     string translatdir = path_cat(recoll_datadir, "translations");
@@ -139,32 +139,52 @@
     // QTextCodec::locale() returns $LANG
     translator.load( QString("recoll_") + QTextCodec::locale(), 
 		     translatdir.c_str() );
-    a.installTranslator( &translator );
+    app.installTranslator( &translator );
 
     rwSettings(false);
 
     string reason;
     rclconfig = recollinit(recollCleanup, sigcleanup, reason);
     if (!rclconfig || !rclconfig->ok()) {
-	QString msg = a.translate("Main", "Configuration problem: ");
+	QString msg = app.translate("Main", "Configuration problem: ");
 	msg += reason;
 	QMessageBox::critical(0, "Recoll",  msg);
 	exit(1);
     }
 
     // Create main window and set its size to previous session's
+#ifdef WITH_KDE
+#if 0
+    if (app.isRestored()) {
+	RESTORE(RclMain);
+    } else {
+#endif
+        // no session.. just start up normally
+        KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+        /// @todo do something with the command line args here
+	qInitImages_recoll();
+        mainWindow = new RclMain;
+        app.setMainWidget( mainWindow );
+        mainWindow->show();
+
+        args->clear();
+
+	//    }
+#else
     RclMain w;
     mainWindow = &w;
-    QSize s(prefs_mainwidth, prefs_mainheight);
-    w.resize(s);
-
-    w.sSearch->allTermsCB->setChecked(prefs_ssall);
+#endif
+    QSize s(prefs.mainwidth, prefs.mainheight);
+    mainWindow->resize(s);
+
+
+    mainWindow->sSearch->allTermsCB->setChecked(prefs.ssall);
 
     if (rclconfig->getConfParam(string("dbdir"), dbdir) == 0) {
 	// Note: this will have to be replaced by a call to a
 	// configuration buildin dialog for initial configuration
 	QMessageBox::critical(0, "Recoll",
-			      a.translate("Main", 
+			      app.translate("Main", 
 					  "No db directory in configuration"));
 	exit(1);
     }
@@ -173,18 +193,19 @@
     rcldb = new Rcl::Db;
 
     // Connect exit handlers etc..
-    a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
-    QTimer *timer = new QTimer(&a);
-    w.connect(timer, SIGNAL(timeout()), &w, SLOT(periodic100()));
+    app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
+    QTimer *timer = new QTimer(&app);
+    mainWindow->connect(timer, SIGNAL(timeout()), 
+			mainWindow, SLOT(periodic100()));
     timer->start(100);
 
     if (!rcldb->open(dbdir, Rcl::Db::DbRO)) {
 	startindexing = 1;
 	switch (QMessageBox::
 		question(0, "Recoll",
-			 a.translate("Main", "Could not open database in ")+
+			 app.translate("Main", "Could not open database in ")+
 			 QString(dbdir) +
-			 a.translate("Main", 
+			 app.translate("Main", 
 				     ".\n"
 				     "Click Cancel if you want to edit the configuration file before indexation starts, or Ok to let it proceed."),
 				      "Ok",
@@ -196,75 +217,10 @@
 	}
     }
 
+    mainWindow->show();
     start_idxthread(*rclconfig);
 
     // Let's go
-    w.show();
-    return a.exec();
-}
-
-const static char *htmlbrowserlist = 
-    "opera konqueror firefox mozilla netscape";
-// Search for and launch an html browser for the documentation. If the
-// user has set a preference, we use it directly instead of guessing.
-bool startHelpBrowser(const string &iurl)
-{
-    string url;
-    if (iurl.empty()) {
-	url = path_cat(recoll_datadir, "doc");
-	url = path_cat(url, "usermanual.html");
-	url = string("file://") + url;
-    } else
-	url = iurl;
-
-
-    // If the user set a preference with an absolute path then things are
-    // simple
-    if (!prefs_htmlBrowser.isEmpty() && prefs_htmlBrowser.find('/') != -1) {
-	if (access(prefs_htmlBrowser.ascii(), X_OK) != 0) {
-	    LOGERR(("startHelpBrowser: %s not found or not executable\n",
-		    prefs_htmlBrowser.ascii()));
-	}
-	string cmd = string(prefs_htmlBrowser.ascii()) + " " + url + "&";
-	if (system(cmd.c_str()) == 0)
-	    return true;
-	else 
-	    return false;
-    }
-
-    string searched;
-    if (prefs_htmlBrowser.isEmpty()) {
-	searched = htmlbrowserlist;
-    } else {
-	searched = prefs_htmlBrowser.ascii();
-    }
-    list<string> blist;
-    stringToTokens(searched, blist, " ");
-
-    const char *path = getenv("PATH");
-    if (path == 0)
-	path = "/bin:/usr/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/local/bin";
-
-    list<string> pathl;
-    stringToTokens(path, pathl, ":");
-    
-    // For each browser name, search path and exec/stop if found
-    for (list<string>::const_iterator bit = blist.begin(); 
-	 bit != blist.end(); bit++) {
-	for (list<string>::const_iterator pit = pathl.begin(); 
-	     pit != pathl.end(); pit++) {
-	    string exefile = path_cat(*pit, *bit);
-	    LOGDEB1(("startHelpBrowser: trying %s\n", exefile.c_str()));
-	    if (access(exefile.c_str(), X_OK) == 0) {
-		string cmd = exefile + " " + url + "&";
-		if (system(cmd.c_str()) == 0) {
-		    return true;
-		}
-	    }
-	}
-    }
-
-    LOGERR(("startHelpBrowser: no html browser found. Looked for: %s\n", 
-	    searched.c_str()));
-    return false;
-}
+    return app.exec();
+}
+