comparison main/main.cpp @ 11:0dbd08e365ce

* Add session management support (commitData)
author Chris Cannam
date Tue, 12 Sep 2006 12:15:44 +0000
parents c3ef80114040
children 47bff9f88882
comparison
equal deleted inserted replaced
10:582f4d6e82c7 11:0dbd08e365ce
27 #include <QMessageBox> 27 #include <QMessageBox>
28 #include <QTranslator> 28 #include <QTranslator>
29 #include <QLocale> 29 #include <QLocale>
30 #include <QSettings> 30 #include <QSettings>
31 #include <QIcon> 31 #include <QIcon>
32 #include <QSessionManager>
32 33
33 #include <iostream> 34 #include <iostream>
34 #include <signal.h> 35 #include <signal.h>
35 36
36 //!!! catch trappable signals, cleanup temporary directory etc 37 //!!! catch trappable signals, cleanup temporary directory etc
47 std::cerr << "signalHandler: cleaning up and exiting" << std::endl; 48 std::cerr << "signalHandler: cleaning up and exiting" << std::endl;
48 TempDirectory::getInstance()->cleanup(); 49 TempDirectory::getInstance()->cleanup();
49 exit(0); // without releasing mutex 50 exit(0); // without releasing mutex
50 } 51 }
51 52
53 class SVApplication : public QApplication
54 {
55 public:
56 SVApplication(int argc, char **argv) :
57 QApplication(argc, argv),
58 m_mainWindow(0) { }
59 virtual ~SVApplication() { }
60
61 void setMainWindow(MainWindow *mw) { m_mainWindow = mw; }
62 void releaseMainWindow() { m_mainWindow = 0; }
63
64 virtual void commitData(QSessionManager &manager) {
65 if (!m_mainWindow) return;
66 bool mayAskUser = manager.allowsInteraction();
67 bool success = m_mainWindow->commitData(mayAskUser);
68 manager.release();
69 if (!success) manager.cancel();
70 }
71
72 protected:
73 MainWindow *m_mainWindow;
74 };
75
52 int 76 int
53 main(int argc, char **argv) 77 main(int argc, char **argv)
54 { 78 {
55 QApplication application(argc, argv); 79 SVApplication application(argc, argv);
56 80
57 signal(SIGINT, signalHandler); 81 signal(SIGINT, signalHandler);
58 signal(SIGTERM, signalHandler); 82 signal(SIGTERM, signalHandler);
59 83
60 #ifndef Q_WS_WIN32 84 #ifndef Q_WS_WIN32
87 // Permit size_t and PropertyName to be used as args in queued signal calls 111 // Permit size_t and PropertyName to be used as args in queued signal calls
88 qRegisterMetaType<size_t>("size_t"); 112 qRegisterMetaType<size_t>("size_t");
89 qRegisterMetaType<PropertyContainer::PropertyName>("PropertyContainer::PropertyName"); 113 qRegisterMetaType<PropertyContainer::PropertyName>("PropertyContainer::PropertyName");
90 114
91 MainWindow gui; 115 MainWindow gui;
116 application.setMainWindow(&gui);
92 117
93 QDesktopWidget *desktop = QApplication::desktop(); 118 QDesktopWidget *desktop = QApplication::desktop();
94 QRect available = desktop->availableGeometry(); 119 QRect available = desktop->availableGeometry();
95 120
96 int width = available.width() * 2 / 3; 121 int width = available.width() * 2 / 3;
127 int rv = application.exec(); 152 int rv = application.exec();
128 std::cerr << "application.exec() returned " << rv << std::endl; 153 std::cerr << "application.exec() returned " << rv << std::endl;
129 154
130 cleanupMutex.lock(); 155 cleanupMutex.lock();
131 TempDirectory::getInstance()->cleanup(); 156 TempDirectory::getInstance()->cleanup();
157 application.releaseMainWindow();
132 158
133 return rv; 159 return rv;
134 } 160 }