3 /// Entry point for barrybackup GUI
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.
26 #include <libglademm.h>
27 #include <barry/barry.h>
28 #include "BackupWindow.h"
33 // The catch-all handler for exceptions that occur inside signals
35 void main_exception_handler()
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());
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
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'.");
57 msg
.set_message(e
.what());
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());
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
[])
97 old_unexpected_handler
= std::set_unexpected(&unexpected_handler
);
98 old_terminate_handler
= std::set_terminate(&terminate_handler
);
102 using namespace Glib
;
103 OptionEntry debug_opt
;
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
);
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
;
146 main_exception_handler();