patch: simple session management

Frank Osterfeld <[email protected]> Tue, 16 Mar 2004 00:58:37 +0100
Newsgroups gmane.comp.kde.devel.knowit
Message-ID <[email protected]>
--Boundary-00=_tMkVAHZsRdIBGTP
Content-Type: text/plain;
  charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi,

another small patch: 

I implemented session management as described in 
http://developer.kde.org/documentation/library/kdeqt/kde3arch/session.html

At the moment it only stores the opened file and reloads it when the session 
is restored. Actually I think there isn't anything else to be stored at 
present.

Regards,

Frank



--Boundary-00=_tMkVAHZsRdIBGTP
Content-Type: text/x-diff;
  charset="us-ascii";
  name="session.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="session.diff"

diff -u knowit-0.10beta4-original/src/knowit.cpp knowit-0.10beta4/src/knowit.cpp
--- knowit-0.10beta4-original/src/knowit.cpp	2004-03-14 18:11:36.000000000 +0100
+++ knowit-0.10beta4/src/knowit.cpp	2004-03-16 00:37:25.000000000 +0100
@@ -1269,3 +1269,15 @@
    kapp->clipboard()->setText(link.link, QClipboard::Selection);
 }
 
+   
+void Knowit::saveProperties(KConfig* config)
+{
+  config->writeEntry("File", filename.path());
+}
+   
+void Knowit::readProperties(KConfig* config)
+{
+  filename = config->readEntry("File");
+  if (!filename.isEmpty())
+    open(filename);
+}
diff -u knowit-0.10beta4-original/src/knowit.h knowit-0.10beta4/src/knowit.h
--- knowit-0.10beta4-original/src/knowit.h	2004-03-14 18:11:34.000000000 +0100
+++ knowit-0.10beta4/src/knowit.h	2004-03-16 00:41:51.000000000 +0100
@@ -82,6 +82,13 @@
     KAction *actionCut, *actionCopy, *actionUndo, *actionRedo;
 
     enum {StatusText = 1, StatusOvr = 2};    
+    
+  protected:
+    /** session management: saves state of application */    
+    virtual void saveProperties(KConfig* config);
+    /** session management: reloads state */
+    virtual void readProperties(KConfig* config);
+   
   public:
     /** Constructor of main window */
     Knowit(QWidget* parent=0, const char *name=0);
diff -u knowit-0.10beta4-original/src/main.cpp knowit-0.10beta4/src/main.cpp
--- knowit-0.10beta4-original/src/main.cpp	2004-03-14 18:11:36.000000000 +0100
+++ knowit-0.10beta4/src/main.cpp	2004-03-16 00:41:21.000000000 +0100
@@ -44,8 +44,14 @@
   KCmdLineArgs::addCmdLineOptions( options ); 
 
   KnowitApplication a(true, true);
-
-  Knowit *knowit = new Knowit(0, "KnowIt");
-  a.setMainWidget(knowit);
+      
+  if (kapp->isRestored())
+    RESTORE(Knowit)
+  else
+  {  
+    Knowit* knowit = new Knowit(0, "KnowIt");
+    a.setMainWidget(knowit);
+  }
+  
   return a.exec();
 }

--Boundary-00=_tMkVAHZsRdIBGTP--



-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click