- moved Interface implementation to usbwrap.cc file
[barry.git] / gui / src / main.cc
blobff93c9c5ca375584d72750c47586b7d5a7e2b900
1 ///
2 /// \file main.cc
3 /// Entry point for barrybackup GUI
4 ///
6 /*
7 Copyright (C) 2007, 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 <gtkmm.h>
25 #include <libglademm.h>
26 #include <barry/barry.h>
27 #include "BackupWindow.h"
28 #include "util.h"
31 // The catch-all handler for exceptions that occur inside signals
33 void main_exception_handler()
35 try {
36 throw;
38 catch( Glib::Exception &e ) {
39 std::cerr << "Glib::Exception caught in main: " << std::endl;
40 std::cerr << e.what() << std::endl;
41 Gtk::MessageDialog msg(e.what());
42 msg.run();
44 catch( std::exception &e ) {
45 std::cerr << "std::exception caught in main: " << std::endl;
46 std::cerr << e.what() << std::endl;
47 Gtk::MessageDialog msg(e.what());
48 msg.run();
54 // These are for debugging... hopefully should never need them in the field,
55 // but you never know...
58 void (*old_unexpected_handler)() = 0;
59 void unexpected_handler()
61 std::cerr << "main.cc: Unexpected exception detected - check your throw() specifications" << std::endl;
62 (*old_unexpected_handler)();
65 void (*old_terminate_handler)() = 0;
66 void terminate_handler()
68 std::cerr << "main.cc: terminate_handler() called - exception handling "
69 "could not complete, most likely due to exception inside "
70 "a destructor or catch()" << std::endl;
71 (*old_terminate_handler)();
76 int main(int argc, char *argv[])
78 old_unexpected_handler = std::set_unexpected(&unexpected_handler);
79 old_terminate_handler = std::set_terminate(&terminate_handler);
81 Glib::thread_init();
83 using namespace Glib;
84 OptionEntry debug_opt;
85 debug_opt.set_flags(
86 OptionEntry::FLAG_NO_ARG |
87 OptionEntry::FLAG_IN_MAIN |
88 OptionEntry::FLAG_OPTIONAL_ARG);
89 debug_opt.set_short_name('d');
90 debug_opt.set_long_name("debug-output");
91 debug_opt.set_description("Enable protocol debug output to stdout/stderr");
93 OptionGroup option_group("barry",
94 "Options specific to the Barry Backup application.",
95 "Options specific to the Barry Backup application.");
96 bool debug_flag = false;
97 option_group.add_entry(debug_opt, debug_flag);
99 OptionContext option_context("Backup program for the Blackberry Handheld");
100 option_context.add_group(option_group);
102 Gtk::Main app(argc, argv, option_context);
103 Glib::add_exception_handler( sigc::ptr_fun(main_exception_handler) );
105 Barry::Init(debug_flag);
107 try {
109 Glib::RefPtr<Gnome::Glade::Xml> refXml = LoadXml("BackupWindow.glade");
111 BackupWindow *pWnd = 0;
112 refXml->get_widget_derived("BackupWindow", pWnd);
113 std::auto_ptr<BackupWindow> apWnd(pWnd);
115 Gtk::Main::run(*pWnd);
118 catch(...) {
119 main_exception_handler();
120 return 1;