00001
00002
00003
00004
00005
00006
00007 #ifndef SERVER_H
00008 #define SERVER_H
00009
00010
00011 #define QT_CLEAN_NAMESPACE 1
00012 #include <tqobject.h>
00013 #include <tqstring.h>
00014 #include <tqstringlist.h>
00015 #include <tqsocketnotifier.h>
00016 #include <tqptrlist.h>
00017 #include <tqvaluelist.h>
00018 #include <tqcstring.h>
00019 #include <tqdict.h>
00020 #include <tqptrqueue.h>
00021 #include <tqptrdict.h>
00022 #include <kapplication.h>
00023 #include <tqtimer.h>
00024 #include <dcopobject.h>
00025
00026 #include "server2.h"
00027
00028 #include "KSMServerInterface.h"
00029
00030 #define SESSION_PREVIOUS_LOGOUT "saved at previous logout"
00031 #define SESSION_BY_USER "saved by user"
00032
00033 typedef TQValueList<TQCString> QCStringList;
00034 class KSMListener;
00035 class KSMConnection;
00036 class KSMClient;
00037
00038 enum SMType { SM_ERROR, SM_WMCOMMAND, SM_WMSAVEYOURSELF };
00039 struct SMData
00040 {
00041 SMType type;
00042 TQStringList wmCommand;
00043 TQString wmClientMachine;
00044 TQString wmclass1, wmclass2;
00045 };
00046 typedef TQMap<WId,SMData> WindowMap;
00047
00048 class KSMServer : public TQObject, public KSMServerInterface
00049 {
00050 Q_OBJECT
00051 K_DCOP
00052 k_dcop:
00053 void notifySlot(TQString,TQString,TQString,TQString,TQString,int,int,int,int);
00054 void logoutSoundFinished(int,int);
00055 void autoStart0Done();
00056 void autoStart1Done();
00057 void autoStart2Done();
00058 void kcmPhase1Done();
00059 void kcmPhase2Done();
00060 public:
00061 KSMServer( const TQString& windowManager, bool only_local );
00062 ~KSMServer();
00063
00064 static KSMServer* self();
00065
00066 void* watchConnection( IceConn iceConn );
00067 void removeConnection( KSMConnection* conn );
00068
00069 KSMClient* newClient( SmsConn );
00070 void deleteClient( KSMClient* client );
00071
00072
00073 void saveYourselfDone( KSMClient* client, bool success );
00074 void interactRequest( KSMClient* client, int dialogType );
00075 void interactDone( KSMClient* client, bool cancelShutdown );
00076 void phase2Request( KSMClient* client );
00077
00078
00079 void ioError( IceConn iceConn );
00080
00081
00082 void clientSetProgram( KSMClient* client );
00083 void clientRegistered( const char* previousId );
00084
00085
00086 void restoreSession( TQString sessionName );
00087 void startDefaultSession();
00088
00089 void shutdown( KApplication::ShutdownConfirm confirm,
00090 KApplication::ShutdownType sdtype,
00091 KApplication::ShutdownMode sdmode );
00092
00093 virtual void suspendStartup( TQCString app );
00094 virtual void resumeStartup( TQCString app );
00095
00096 bool checkStatus( bool &logoutConfirmed, bool &maysd,
00097 KApplication::ShutdownConfirm confirm,
00098 KApplication::ShutdownType sdtype,
00099 KApplication::ShutdownMode sdmode );
00100
00101 public slots:
00102 void cleanUp();
00103
00104 private slots:
00105 void newConnection( int socket );
00106 void processData( int socket );
00107 void restoreSessionInternal();
00108 void restoreSessionDoneInternal();
00109
00110 void protectionTimeout();
00111 void timeoutQuit();
00112 void timeoutWMQuit();
00113 void knotifyTimeout();
00114 void kcmPhase1Timeout();
00115 void kcmPhase2Timeout();
00116 void pendingShutdownTimeout();
00117
00118 void autoStart0();
00119 void autoStart1();
00120 void autoStart2();
00121 void tryRestoreNext();
00122 void startupSuspendTimeout();
00123
00124 private:
00125 void handlePendingInteractions();
00126 void completeShutdownOrCheckpoint();
00127 void startKilling();
00128 void performStandardKilling();
00129 void completeKilling();
00130 void killWM();
00131 void completeKillingWM();
00132 void cancelShutdown( KSMClient* c );
00133 void killingCompleted();
00134
00135 void discardSession();
00136 void storeSession();
00137
00138 void startProtection();
00139 void endProtection();
00140
00141 void startApplication( TQStringList command,
00142 const TQString& clientMachine = TQString::null,
00143 const TQString& userId = TQString::null );
00144 void executeCommand( const TQStringList& command );
00145
00146 bool isWM( const KSMClient* client ) const;
00147 bool isWM( const TQString& program ) const;
00148 bool defaultSession() const;
00149 void setupXIOErrorHandler();
00150
00151 void shutdownInternal( KApplication::ShutdownConfirm confirm,
00152 KApplication::ShutdownType sdtype,
00153 KApplication::ShutdownMode sdmode,
00154 TQString bootOption = TQString::null );
00155
00156 void performLegacySessionSave();
00157 void storeLegacySession( KConfig* config );
00158 void restoreLegacySession( KConfig* config );
00159 void restoreLegacySessionInternal( KConfig* config, char sep = ',' );
00160 TQStringList windowWmCommand(WId w);
00161 TQString windowWmClientMachine(WId w);
00162 WId windowWmClientLeader(WId w);
00163 TQCString windowSessionId(WId w, WId leader);
00164
00165 bool checkStartupSuspend();
00166 void finishStartup();
00167 void resumeStartupInternal();
00168
00169
00170 void logout( int, int, int );
00171 virtual void logoutTimed( int, int, TQString );
00172 TQStringList sessionList();
00173 TQString currentSession();
00174 void saveCurrentSession();
00175 void saveCurrentSessionAs( TQString );
00176
00177 private:
00178 TQPtrList<KSMListener> listener;
00179 TQPtrList<KSMClient> clients;
00180
00181 enum State
00182 {
00183 Idle,
00184 LaunchingWM, AutoStart0, KcmInitPhase1, AutoStart1, Restoring, FinishingStartup,
00185 Shutdown, Checkpoint, Killing, KillingWM, WaitingForKNotify
00186 };
00187 State state;
00188 bool dialogActive;
00189 bool saveSession;
00190 int wmPhase1WaitingCount;
00191 int saveType;
00192 TQMap< TQCString, int > startupSuspendCount;
00193
00194 KApplication::ShutdownType shutdownType;
00195 KApplication::ShutdownMode shutdownMode;
00196 TQString bootOption;
00197
00198 bool clean;
00199 KSMClient* clientInteracting;
00200 TQString wm;
00201 TQString sessionGroup;
00202 TQString sessionName;
00203 TQCString launcher;
00204 TQTimer protectionTimer;
00205 TQTimer restoreTimer;
00206 TQString xonCommand;
00207 int logoutSoundEvent;
00208 TQTimer knotifyTimeoutTimer;
00209 TQTimer startupSuspendTimeoutTimer;
00210 bool waitAutoStart2;
00211 bool waitKcmInit2;
00212 TQTimer pendingShutdown;
00213 KApplication::ShutdownConfirm pendingShutdown_confirm;
00214 KApplication::ShutdownType pendingShutdown_sdtype;
00215 KApplication::ShutdownMode pendingShutdown_sdmode;
00216
00217
00218 void upAndRunning( const TQString& msg );
00219 void publishProgress( int progress, bool max = false );
00220
00221
00222 int appsToStart;
00223 int lastAppStarted;
00224 TQString lastIdStarted;
00225
00226 TQStringList excludeApps;
00227
00228 WindowMap legacyWindows;
00229 };
00230
00231 #endif