File oooqs-1.0_rc3-monitor-running-instance.patch of Package OpenOffice_org-Quickstarter
--- oooqs/oooqs.cpp.old 2008-05-20 21:19:13.000000000 +0200
+++ oooqs/oooqs.cpp 2008-05-21 19:36:09.000000000 +0200
@@ -32,6 +32,8 @@
#include <kmessagebox.h>
#include <kstandarddirs.h>
+#define MONITOR_TIMER_INTERVAL 1000
+
#define Icon(x) KGlobal::instance()->iconLoader()->loadIcon(x, KIcon::Toolbar)
OooQs::OooQs(KAboutData* aboutDta, KDialog* d, QWidget *parent, const char *name) : KSystemTray(parent, name), aboutDialog(d)
@@ -148,13 +150,14 @@ OooQs::OooQs(KAboutData* aboutDta, KDial
instance << soffice << "-nologo" << "-nodefault";
- /** Make sure that instance is automatically restarted when it gets closed */
- connect(&instance, SIGNAL (processExited(KProcess*)), SLOT (restartOfficeWait()));
+ instancePIDFile="";
+ connect( &monitorTimer, SIGNAL(timeout()), this, SLOT(keepRunningInstance()) );
/** Check if the quickstart should be enabled */
if (quickstartEnabled){
- /** Try to start instance for the first time */
- restartOffice(true);
+ if (!findRunningInstance())
+ startQuickstarterInstance();
+ monitorTimer.start(MONITOR_TIMER_INTERVAL);
}
}
@@ -234,37 +237,35 @@ void OooQs::startWeb(){
startInstances("-web");
}
-/** Restarts OpenOffice if removed from memory and try to wait if an other OOo isntance is already running */
-void OooQs::restartOfficeWait(){
- restartOffice(false);
-}
-
-/** Restarts OpenOffice if removed from memory. */
-void OooQs::restartOffice(bool immediately){
- /** at first check if the quickstart-mode is enabled */
- if (quickstartEnabled){
- /** check, if the Master Instance is running ! */
- if (!instance.isRunning()) {
- if (!immediately) {
- int waitSec=120;
- while ((isAnotherOOoInstanceRunning()) && (--waitSec >= 0))
- sleep(1);
- }
- if (!isAnotherOOoInstanceRunning()) {
- /** we dont need any Communication ! */
- instance.start(KProcess::NotifyOnExit,KProcess::NoCommunication);
- } else {
- /** another OOo isntance is running then each new OOo instance
- will be immediately exited, so the quickstarter mode will not
- work and must be disabled */
- KMessageBox::information(preferencesDialog, i18n("The quickstart mode cannot be enabled at this time because OpenOffice.org is already in use.\n"
- "\n"
- "You can enable the quickstart mode in the Quickstarter configuration dialog after you have stopped the current OpenOffice.org."));
- preferencesDialog->enableQuick->setChecked(false);
- quickstartEnabled=false;
- /** save changed value into the config file */
- changedConfig();
- }
+/** Check if the quickstarter instance is still running; start another one if needed*/
+void OooQs::keepRunningInstance(){
+ if ( instancePIDFile.isEmpty() || (!QFile::exists(instancePIDFile)) )
+ startQuickstarterInstance();
+}
+
+/** Start the quickstarter instance of OOo on background */
+void OooQs::startQuickstarterInstance() {
+ if (quickstartEnabled) {
+ /** stop the timer for now */
+ bool wasTimerActive = monitorTimer.isActive();
+ monitorTimer.stop();
+ /** we dont need any Communication ! */
+ instance.start(KProcess::NotifyOnExit,KProcess::NoCommunication);
+ /** give it 2 seconds to start; it is done via the oosplash.bin now... */
+ sleep(1);
+ /** FIXME: the first sleep seems to be ignored from some reasons on openSUSE-11.0 */
+ sleep(1);
+ if (findRunningInstance()) {
+ /** successfully started */
+ if (wasTimerActive)
+ monitorTimer.start(MONITOR_TIMER_INTERVAL);
+ } else {
+ /** did not start from some reasons */
+ KMessageBox::information(preferencesDialog, i18n("Failed to start OpenOffice.org in the backgroud. The quickstart mode is not supported and will be disabled."));
+ preferencesDialog->enableQuick->setChecked(false);
+ quickstartEnabled=false;
+ /** save changed value into the config file */
+ changedConfig();
}
}
}
@@ -384,7 +385,9 @@ void OooQs::rereadConfig(){
}
}else{
quickstartEnabled=true;
- restartOffice(true);
+ if (!findRunningInstance())
+ startQuickstarterInstance();
+ monitorTimer.start(MONITOR_TIMER_INTERVAL);
}
}
if (open){
@@ -891,7 +894,7 @@ void OooQs::freeDirList(struct dirent **
}
/** check if the soffice.bin is runnig by the user $USER */
-int OooQs::isAnotherOOoInstanceRunning()
+int OooQs::findRunningInstance()
{
struct dirent **procList=NULL;
int dirEntNum;
@@ -910,6 +913,8 @@ int OooQs::isAnotherOOoInstanceRunning()
/** the /proc dir can not be read */
return 0;
+ instancePIDFile="";
+
/** scan each process */
for(i = 0; i < dirEntNum; i++) {
strcpy(searchedFile, "/proc/");
@@ -926,6 +931,7 @@ int OooQs::isAnotherOOoInstanceRunning()
if(searchFile(searchedFile, searchedUSER)) {
/** yes, it does. Another OOo instance is already running */
freeDirList(procList, dirEntNum);
+ instancePIDFile=searchedFile;
return 1;
}
}
--- oooqs/oooqs.h.old 2008-05-20 21:19:13.000000000 +0200
+++ oooqs/oooqs.h 2008-05-21 18:59:48.000000000 +0200
@@ -36,6 +36,8 @@
#include <kpopupmenu.h>
#include <kprocess.h>
#include <ksystemtray.h>
+#include <qtimer.h>
+
/** OooQs is the base class of the project */
class OooQs : public KSystemTray
@@ -85,6 +87,10 @@ private: // Private attributes
KDialog* aboutDialog;
/** The KProcess that starts and control OpenOffice.org in quickstart-mode. */
KProcess instance;
+ /** A file from /proc related to the running OOo instance. It is used to check if it is still running. */
+ QString instancePIDFile;
+ /** The timer to monitor the quickstarter instance */
+ QTimer monitorTimer;
/** Saves the path to the soffice startscript/executable */
QString soffice;
/** Saves if the quickstart should be enabled */
@@ -128,8 +134,8 @@ private slots: // Private slots
void startWriter();
/** Executes the about-dialog. */
void showAbout();
- /** Restarts OpenOffice if removed from memory and try to wait if an other OOo isntance is already running. */
- void restartOfficeWait();
+ /** Check if the quickstarter instance is still running; start another one if needed */
+ void keepRunningInstance();
/** Delete the process. */
void delProcess(KProcess* process);
/** Call this to open the start-dialog. */
@@ -149,14 +155,14 @@ private:
void setClickAction();
/** Set the texts on the actions opening the connected module. */
void updateActions(void);
- /** Restarts OpenOffice if removed from memory. */
- void restartOffice(bool immediately);
+ /** Start the quickstarter instance of OOo on background */
+ void startQuickstarterInstance();
/** search file for the string */
int searchFile(const char *path, const char *string);
/** free the array with dir entries allocated by the function scandir */
void freeDirList(struct dirent **dirList, int dirEntNum);
- /** check if the soffice.bin is runnig by the user $USER */
- int isAnotherOOoInstanceRunning();
+ /** find if the soffice.bin is runnig by the user $USER */
+ int findRunningInstance();
signals:
/** Emit when a click was registered */
void click();