int main(int argc, char **argv) { manitou_application app(argc,argv); gl_pApplication=&app; #if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) // The location of the data files depends on the prefix choosen at configure // time except under windows. QString s = QString(MANITOU_DATADIR); QString manitou_tr_path = s + "/translations"; QString qt_tr_path = QLibraryInfo::location(QLibraryInfo::TranslationsPath); gl_xpm_path = s + "/icons"; gl_help_path = s + "/help"; #elif defined(Q_OS_WIN) // under windows, the data directories are expected to be at the same level // than the executable file QString s = QApplication::applicationDirPath(); QString qt_tr_path = QLibraryInfo::location(QLibraryInfo::TranslationsPath); QString manitou_tr_path = s + "/translations"; gl_xpm_path = s + "/icons"; gl_help_path = s + "/help"; #elif defined(Q_OS_MAC) // we use embedded resources on Mac QString qt_tr_path = QLibraryInfo::location(QLibraryInfo::TranslationsPath); gl_xpm_path = ":/images"; QString manitou_tr_path = ":/translations"; #endif const char* cnx_string=NULL; QString conf_name; bool explicit_config=false; while(1) { int option_index = 0; static optstruct long_options[] = { {"debug-output", 1, 0, 'l'}, {"debug-window", 1, 0, 'w'}, {"config", 1, 0, 'c'}, {"dbcnx", 1, 0, 'd'}, {"help", 1, 0, 'h'}, {0, 0, 0, 0} }; int c = GETOPT_LONG(argc, argv, "d:c:h:", long_options, &option_index); if (c == -1) break; switch (c) { case 0: printf ("option %s", long_options[option_index].name); if (OPTARG) printf (" with arg %s", OPTARG); printf ("\n"); break; case '?': usage(argv[0]); break; case 'h': usage(argv[0]); break; case 'c': conf_name = OPTARG; explicit_config=true; break; case 'l': global_debug_level = OPTARG?atoi(OPTARG):10; break; case 'w': global_debug_level = OPTARG?atoi(OPTARG):10; global_debug_window = 1; break; case 'd': cnx_string = OPTARG; break; } } if (OPTIND < argc && !cnx_string) { /* compatibility with earlier versions: if there are non-named arguments on the command line, they will be interpreted as a connection string */ cnx_string = argv[OPTIND]; } QTranslator translator; QTranslator translator_qt; QLocale locale = QLocale::system(); // search for a translation file, except for the C locale if (locale.name() != QLocale::c().name()) { if (translator_qt.load(QString("qt_")+locale.name(), qt_tr_path)) app.installTranslator(&translator_qt); if (translator.load(QString("manitou_")+locale.name(), manitou_tr_path)) { app.installTranslator(&translator); } else { QString tq = QString("manitou_")+locale.name(); DBG_PRINTF(3, "Failed to load translation file %s", tq.toLocal8Bit().constData()); } } if (conf_name.isEmpty()) { // then configuration is hostname-OSname QString hostname=QHostInfo::localHostName().toLower(); if (hostname.isEmpty()) hostname="unknown"; QString uname; #ifndef Q_OS_WIN struct utsname u; if (::uname(&u)==0 && u.sysname[0]) { uname = QString(u.sysname).toLower(); } #else uname="windows"; #endif conf_name = hostname + "-" + uname; } int connected=0; if (cnx_string==NULL) { // get the connection parameters from a dialog box QString qcs; login_dialog dlg; QSettings settings("Manitou-Mail", "manitou-ui"); dlg.set_login(settings.value("login").toString()); dlg.set_dbname(settings.value("dbname").toString()); dlg.set_host(settings.value("host").toString()); dlg.set_params(settings.value("params").toString()); dlg.set_focus(); do { if (dlg.exec()==1) { qcs = dlg.connect_string(); } else { helper::close(); exit(0); // exit if connection dialog closed with 'Cancel' } QString errstr; if (!(connected=ConnectDb(qcs.toLocal8Bit(), &errstr))) { QMessageBox::critical(NULL, QObject::tr("Fatal database error"), QObject::tr("Error while connecting to the database:\n")+errstr); } else { settings.setValue("login", dlg.login()); settings.setValue("dbname", dlg.dbnames()); // stringlist settings.setValue("host", dlg.host()); settings.setValue("params", dlg.params()); } } while (!connected); } else { QString errstr; if (!ConnectDb(cnx_string, &errstr)) { QMessageBox::critical(NULL, QObject::tr("Fatal database error"), QObject::tr("Error while connecting to the database:\n")+errstr); exit(1); } } if (!explicit_config) { QByteArray qb = conf_name.toLatin1(); printf("Configuration used: %s\n", qb.constData()); fflush(stdout); } global_conf.set_name(conf_name); global_conf.init(); global_conf.apply(); msgs_filter filter; filter.m_sql_stmt="0"; #ifdef Q_OS_UNIX gl_pApplication->setAttribute(Qt::AA_DontShowIconsInMenus, false); #endif /* Instantiate the user in the database if necessary. Ideally we should ask for a fullname if not already known, but there's no GUI support for that yet */ user::create_if_missing(QString::null); users_repository::fetch(); message_port::init(); msg_status_cache::init_db(); msg_list_window* w = new msg_list_window(&filter,0); w->show(); app.connect(&app, SIGNAL(lastWindowClosed()), SLOT(quit())); app.connect(&app, SIGNAL(aboutToQuit()), SLOT(cleanup())); app.exec(); DisconnectDb(); DBG_PRINTF(1, "end"); return 0; }
int main(int argc, char **argv) { manitou_application app(argc,argv); gl_pApplication=&app; #if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) // The location of the data files depends on the prefix choosen at configure // time except under windows. QString s = QString(MANITOU_DATADIR); QString manitou_tr_path = s + "/translations"; QString qt_tr_path = QLibraryInfo::location(QLibraryInfo::TranslationsPath); gl_xpm_path = s + "/icons"; gl_help_path = s + "/help"; #elif defined(Q_OS_WIN) // under windows, the data directories are expected to be at the same level // than the executable file QString s = QApplication::applicationDirPath(); QString qt_tr_path = QLibraryInfo::location(QLibraryInfo::TranslationsPath); QString manitou_tr_path = s + "/translations"; gl_xpm_path = s + "/icons"; gl_help_path = s + "/help"; #elif defined(Q_OS_MAC) // we use embedded resources on Mac QString qt_tr_path = QLibraryInfo::location(QLibraryInfo::TranslationsPath); gl_xpm_path = ":/images"; QString s = QApplication::applicationDirPath(); gl_help_path = s + "/help"; QString manitou_tr_path = s + "/translations"; #endif const char* cnx_string=NULL; QString conf_name; bool explicit_config=false; while(1) { int option_index = 0; static optstruct long_options[] = { {"debug-output", 1, 0, 'l'}, {"debug-window", 1, 0, 'w'}, {"config", 1, 0, 'c'}, {"dbcnx", 1, 0, 'd'}, {"help", 1, 0, 'h'}, {0, 0, 0, 0} }; int c = GETOPT_LONG(argc, argv, "d:c:h:", long_options, &option_index); if (c == -1) break; switch (c) { case 0: printf ("option %s", long_options[option_index].name); if (OPTARG) printf (" with arg %s", OPTARG); printf ("\n"); break; case '?': usage(argv[0]); break; case 'h': usage(argv[0]); break; case 'c': conf_name = OPTARG; explicit_config=true; break; case 'l': global_debug_level = OPTARG?atoi(OPTARG):10; break; case 'w': global_debug_level = OPTARG?atoi(OPTARG):10; global_debug_window = 1; break; case 'd': cnx_string = OPTARG; break; } } if (OPTIND < argc && !cnx_string) { /* compatibility with earlier versions: if there are non-named arguments on the command line, they will be interpreted as a connection string */ cnx_string = argv[OPTIND]; } QTranslator translator; QTranslator translator_qt; QLocale locale = QLocale::system(); // search for a translation file, except for the C locale if (locale.name() != QLocale::c().name()) { if (translator_qt.load(QString("qt_")+locale.name(), qt_tr_path)) app.installTranslator(&translator_qt); if (translator.load(QString("manitou_")+locale.name(), manitou_tr_path)) { app.installTranslator(&translator); } else { QString tq = QString("manitou_")+locale.name(); DBG_PRINTF(3, "Failed to load translation file %s", tq.toLocal8Bit().constData()); } } if (conf_name.isEmpty()) { // then configuration is hostname-OSname QString hostname=QHostInfo::localHostName().toLower(); if (hostname.isEmpty()) hostname="unknown"; QString uname; #ifndef Q_OS_WIN struct utsname u; if (::uname(&u)==0 && u.sysname[0]) { uname = QString(u.sysname).toLower(); } #else uname="windows"; #endif conf_name = hostname + "-" + uname; } /* Call createUuid() before creating any window as a workaround against QTBUG-11080 or QTBUG-11213 in Qt-4.6.2 on Linux. Otherwise, createUuid() may return a UUID that is always the same when creating a new Message-Id later on. The fix for this Qt bug has not been backported in Ubuntu-10.04 LTS at this time (2012-10-08). */ (void)QUuid::createUuid(); if (cnx_string==NULL) { login_dialog dlg; if (dlg.exec() == QDialog::Rejected) return 0; } else { QString errstr; if (!ConnectDb(cnx_string, &errstr)) { QMessageBox::critical(NULL, QObject::tr("Fatal database error"), QObject::tr("Error while connecting to the database:\n")+errstr); return 1; } } if (!explicit_config) { printf("Configuration used: %s\n", conf_name.toLocal8Bit().constData()); } global_conf.set_name(conf_name); global_conf.init(); global_conf.apply(); if (!QFile::exists(gl_xpm_path+"/"+FT_ICON16_QUIT)) { gl_pApplication->display_warning(QObject::tr("Icon files not found at: %1").arg(gl_xpm_path)); } msgs_filter filter; QString sq = get_config().get_string("display/start_query"); filter.m_sql_stmt= sq.isEmpty() ? "0" : sq; #ifdef Q_OS_UNIX gl_pApplication->setAttribute(Qt::AA_DontShowIconsInMenus, false); #endif users_repository::fetch(); message_port::init(); msg_status_cache::init_db(); tags_repository::fetch(); app.setup_desktop_tray_icon(); msg_list_window* w = new msg_list_window(&filter,0); w->show(); app.connect(&app, SIGNAL(lastWindowClosed()), SLOT(quit())); app.connect(&app, SIGNAL(aboutToQuit()), SLOT(cleanup())); app.exec(); DisconnectDb(); return 0; }