Reduced minimum password retry level from 6 to 3
[barry/pauldeden.git] / gui / src / main.cc
blobdaff7578d122ba1b5bc5d430055674db40bd0b8b
1 ///
2 /// \file main.cc
3 /// Entry point for barrybackup GUI
4 ///
6 /*
7 Copyright (C) 2007-2008, 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"
32 // The catch-all handler for exceptions that occur inside signals
34 void main_exception_handler()
36 try {
37 throw;
39 catch( Glib::Exception &e ) {
40 std::cerr << "Glib::Exception caught in main: " << std::endl;
41 std::cerr << e.what() << std::endl;
42 Gtk::MessageDialog msg(e.what());
43 msg.run();
45 catch( Usb::Error &e ) {
46 std::cerr << "Usb::Error caught in main:\n"
47 << e.what() << std::endl;
49 // special check for EBUSY to make the error message
50 // more user friendly
51 Gtk::MessageDialog msg("");
52 if( e.libusb_errcode() == -EBUSY ) {
53 msg.set_message("Device busy. This is likely due to the usb_storage kernel module being loaded. Try 'rmmod usb_storage'.");
55 else {
56 msg.set_message(e.what());
58 msg.run();
60 catch( std::exception &e ) {
61 std::cerr << "std::exception caught in main: " << std::endl;
62 std::cerr << e.what() << std::endl;
63 Gtk::MessageDialog msg(e.what());
64 msg.run();
70 // These are for debugging... hopefully should never need them in the field,
71 // but you never know...
74 void (*old_unexpected_handler)() = 0;
75 void unexpected_handler()
77 std::cerr << "main.cc: Unexpected exception detected - check your throw() specifications" << std::endl;
78 (*old_unexpected_handler)();
81 void (*old_terminate_handler)() = 0;
82 void terminate_handler()
84 std::cerr << "main.cc: terminate_handler() called - exception handling "
85 "could not complete, most likely due to exception inside "
86 "a destructor or catch()" << std::endl;
87 (*old_terminate_handler)();
92 int main(int argc, char *argv[])
94 old_unexpected_handler = std::set_unexpected(&unexpected_handler);
95 old_terminate_handler = std::set_terminate(&terminate_handler);
97 Glib::thread_init();
99 using namespace Glib;
100 OptionEntry debug_opt;
101 debug_opt.set_flags(
102 OptionEntry::FLAG_NO_ARG |
103 OptionEntry::FLAG_IN_MAIN |
104 OptionEntry::FLAG_OPTIONAL_ARG);
105 debug_opt.set_short_name('d');
106 debug_opt.set_long_name("debug-output");
107 debug_opt.set_description("Enable protocol debug output to stdout/stderr");
109 OptionGroup option_group("barry",
110 "Options specific to the Barry Backup application.",
111 "Options specific to the Barry Backup application.");
112 bool debug_flag = false;
113 option_group.add_entry(debug_opt, debug_flag);
115 OptionContext option_context("Backup program for the Blackberry Handheld");
116 option_context.add_group(option_group);
118 Gtk::Main app(argc, argv, option_context);
119 Glib::add_exception_handler( sigc::ptr_fun(main_exception_handler) );
121 Barry::Init(debug_flag);
123 try {
125 Glib::RefPtr<Gnome::Glade::Xml> refXml = LoadXml("BackupWindow.glade");
127 BackupWindow *pWnd = 0;
128 refXml->get_widget_derived("BackupWindow", pWnd);
129 std::auto_ptr<BackupWindow> apWnd(pWnd);
131 Gtk::Main::run(*pWnd);
134 catch(...) {
135 main_exception_handler();
136 return 1;