Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
DISCONTINUED:openSUSE:11.2:Update
OpenOffice_org-Quickstarter
oooqs-1.0_rc3-monitor-running-instance.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File oooqs-1.0_rc3-monitor-running-instance.patch of Package OpenOffice_org-Quickstarter
--- oooqs/oooqs.cpp +++ oooqs/oooqs.cpp @@ -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 @@ 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,38 @@ 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 few seconds to start; check every second to close the options dialog ASAP */ + int max_wait = 8; + int isRunning = 0; + while (!isRunning && (max_wait-- > 0)) { + sleep(1); + isRunning = findRunningInstance(); + } + if (isRunning) { + /** 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 +388,9 @@ } }else{ quickstartEnabled=true; - restartOffice(true); + if (!findRunningInstance()) + startQuickstarterInstance(); + monitorTimer.start(MONITOR_TIMER_INTERVAL); } } if (open){ @@ -891,7 +897,7 @@ } /** 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 +916,8 @@ /** the /proc dir can not be read */ return 0; + instancePIDFile=""; + /** scan each process */ for(i = 0; i < dirEntNum; i++) { strcpy(searchedFile, "/proc/"); @@ -926,6 +934,7 @@ if(searchFile(searchedFile, searchedUSER)) { /** yes, it does. Another OOo instance is already running */ freeDirList(procList, dirEntNum); + instancePIDFile=searchedFile; return 1; } } --- oooqs/oooqs.h +++ oooqs/oooqs.h @@ -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 @@ 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 @@ 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 @@ 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();
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor