lib: added warning checks for unsupported recursion fields in vevent.cc
[barry/progweb.git] / gui / src / main.cc
blob18e4356c83a723b3f2f3d03edd8c8f6755646ef7
1 ///
2 /// \file main.cc
3 /// Entry point for barrybackup GUI
4 ///
6 /*
7 Copyright (C) 2007-2012, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #include <iostream>
23 #include <stdexcept>
24 #include <errno.h>
25 #include <gtkmm.h>
26 #include <libglademm.h>
27 #include <barry/barry.h>
28 #include "BackupWindow.h"
29 #include "util.h"
30 #include "i18n.h"
33 // The catch-all handler for exceptions that occur inside signals
35 void main_exception_handler()
37 try {
38 throw;
40 catch( Glib::Exception &e ) {
41 std::cerr << "Glib::Exception caught in main: " << std::endl;
42 std::cerr << e.what() << std::endl;
43 Gtk::MessageDialog msg(e.what());
44 msg.run();
46 catch( Usb::Error &e ) {
47 std::cerr << "Usb::Error caught in main:\n"
48 << e.what() << std::endl;
50 // special check for EBUSY to make the error message
51 // more user friendly
52 Gtk::MessageDialog msg("");
53 if( e.system_errcode() == -EBUSY ) {
54 msg.set_message("Device busy. This is likely due to the usb_storage kernel module being loaded. Try 'rmmod usb_storage'.");
56 else {
57 msg.set_message(e.what());
59 msg.run();
61 catch( std::exception &e ) {
62 std::cerr << "std::exception caught in main: " << std::endl;
63 std::cerr << e.what() << std::endl;
64 Gtk::MessageDialog msg(e.what());
65 msg.run();
71 // These are for debugging... hopefully should never need them in the field,
72 // but you never know...
75 void (*old_unexpected_handler)() = 0;
76 void unexpected_handler()
78 std::cerr << "main.cc: Unexpected exception detected - check your throw() specifications" << std::endl;
79 (*old_unexpected_handler)();
82 void (*old_terminate_handler)() = 0;
83 void terminate_handler()
85 std::cerr << "main.cc: terminate_handler() called - exception handling "
86 "could not complete, most likely due to exception inside "
87 "a destructor or catch()" << std::endl;
88 (*old_terminate_handler)();
93 int main(int argc, char *argv[])
95 INIT_I18N(PACKAGE);
97 old_unexpected_handler = std::set_unexpected(&unexpected_handler);
98 old_terminate_handler = std::set_terminate(&terminate_handler);
100 Glib::thread_init();
102 using namespace Glib;
103 OptionEntry debug_opt;
104 debug_opt.set_flags(
105 OptionEntry::FLAG_NO_ARG |
106 OptionEntry::FLAG_IN_MAIN |
107 OptionEntry::FLAG_OPTIONAL_ARG);
108 debug_opt.set_short_name('d');
109 debug_opt.set_long_name("debug-output");
110 debug_opt.set_description("Enable protocol debug output to stdout/stderr");
112 OptionGroup option_group("barry",
113 "Options specific to the Barry Backup application.",
114 "Options specific to the Barry Backup application.");
115 bool debug_flag = false;
116 option_group.add_entry(debug_opt, debug_flag);
118 OptionContext option_context("Backup program for the Blackberry Handheld");
119 option_context.add_group(option_group);
121 try {
123 Gtk::Main app(argc, argv, option_context);
124 Glib::add_exception_handler( sigc::ptr_fun(main_exception_handler) );
126 Barry::Init(debug_flag);
128 Glib::RefPtr<Gnome::Glade::Xml> refXml = LoadXml("BackupWindow.glade");
130 BackupWindow *pWnd = 0;
131 refXml->get_widget_derived("BackupWindow", pWnd);
132 std::auto_ptr<BackupWindow> apWnd(pWnd);
134 Gtk::Main::run(*pWnd);
137 catch( Glib::OptionError &oe ) {
138 // Ouch! Not all glibmm versions provide an
139 // easy way to display the official help... so we
140 // at least point the user in the right direction.
141 std::cerr << oe.what() << std::endl;
142 std::cerr << "Try --help or --help-all" << std::endl;
143 return 1;
145 catch(...) {
146 main_exception_handler();
147 return 1;