8 #include "MainWindow.hpp"
13 MainWindow* main_window;
16 static void signal_handler(int signal_id)
18 if (signal_id == SIGTERM) {
20 } else if (signal_id == SIGUSR1) {
21 main_window->nextMonth();
22 } else if (signal_id == SIGUSR2) {
23 main_window->prevMonth();
33 static bool time_handler(GtkWidget *widget)
35 main_window->updateTime();
41 std::cout << PACKAGE_STRING << std::endl;
44 static void usage(const char* const name)
46 std::cerr << "usage: " << name << " [options] [commands]\n"
48 << "\t-h, --help\n\t\tprint this help text and quit\n"
49 << "\t-v, --version\n\t\tprint version info and quit\n"
51 << "\tnext_month, prev_month\n"
52 << "\t\tif program is running, switch the displayed month\n"
53 << "\t\totherwise simply run the program\n"
54 << "\tif no command is given\n"
55 << "\t\tif program is not running, start it\n"
56 << "\t\totherwise stop it\n"
60 int main(int argc, char *argv[])
63 if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) {
66 } else if (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0) {
72 Unique* unique = new Unique();
73 if (unique->isRunning()) {
75 if (argc >= 2 && strcmp(argv[1], "next_month") == 0) {
76 unique->signal(SIGUSR1);
77 } else if (argc >= 2 && strcmp(argv[1], "prev_month") == 0) {
78 unique->signal(SIGUSR2);
84 } catch (UniqueException e) {
85 std::cerr << "Looks like gsimplecal crashed last time."
86 << " Exception message is: " << e.what() << ". Cleaning up."
93 signal(SIGTERM, &signal_handler);
94 signal(SIGUSR1, &signal_handler);
95 signal(SIGUSR2, &signal_handler);
96 signal(SIGCHLD, SIG_IGN);
98 gtk_init(&argc, &argv);
99 main_window = new MainWindow();
101 gtk_signal_connect(GTK_OBJECT(main_window->getWindow()), "destroy",
102 GTK_SIGNAL_FUNC(destroy), NULL);
104 Config* config = Config::getInstance();
105 if (config->show_timezones) {
106 g_timeout_add(30000, (GSourceFunc)time_handler, NULL);
108 if (config->close_on_unfocus) {
109 g_signal_connect(G_OBJECT(main_window->getWindow()), "focus-out-event",
110 GTK_SIGNAL_FUNC(gtk_widget_destroy),
111 GTK_OBJECT(main_window->getWindow()));