main.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <QObject>
00018 #include <vidalia.h>
00019 #include <mainwindow.h>
00020 #include <vmessagebox.h>
00021 #include <procutil.h>
00022 #include <stringutil.h>
00023
00024 #if defined(Q_OS_WIN32)
00025 #include <QSysInfo>
00026 #endif
00027
00028
00029 bool
00030 is_vidalia_running(QString pidfile)
00031 {
00032
00033 qint64 pid = read_pidfile(pidfile);
00034 if (pid > 0) {
00035 #if defined(Q_OS_WIN32)
00036 if (QSysInfo::WindowsVersion == QSysInfo::WV_NT) {
00037
00038
00039
00040 return true;
00041 } else
00042 return (is_process_running(pid));
00043 #else
00044 return (is_process_running(pid));
00045 #endif
00046 }
00047 return false;
00048 }
00049
00050
00051 int
00052 main(int argc, char *argv[])
00053 {
00054 Q_INIT_RESOURCE(vidalia);
00055 QStringList args = char_array_to_stringlist(argv+1, argc-1);
00056
00057
00058
00059
00060 Vidalia vidalia(args, argc, argv);
00061 vNotice("Vidalia %1 using Qt %2").arg(Vidalia::version())
00062 .arg(QT_VERSION_STR);
00063
00064
00065
00066 QString errmsg;
00067 if (vidalia.showUsage()) {
00068 Vidalia::showUsageMessageBox();
00069 return 0;
00070 } else if (!vidalia.validateArguments(errmsg)) {
00071 vError("Unable to apply command-line arguments: %1").arg(errmsg);
00072 VMessageBox::critical(0,
00073 vApp->translate("Vidalia",
00074 QT_TRANSLATE_NOOP("Vidalia", "Invalid Argument")), errmsg,
00075 VMessageBox::Ok);
00076 return 1;
00077 }
00078
00079
00080 QString pidfile = vidalia.pidFile();
00081 if (is_vidalia_running(pidfile)) {
00082 vWarn("Detected another process with pid %1. Is Vidalia already running?")
00083 .arg(get_pid());
00084
00085
00086 int ret = VMessageBox::critical(0,
00087 vApp->translate("Vidalia",
00088 QT_TRANSLATE_NOOP("Vidalia", "Vidalia is already running")),
00089 vApp->translate("Vidalia",
00090 QT_TRANSLATE_NOOP("Vidalia",
00091 "Another Vidalia process is possibly already running. "
00092 "If there really is not another Vidalia process running, "
00093 "you can choose to continue anyway.\n\n"
00094 "Would you like to continue starting Vidalia?")),
00095 VMessageBox::Continue, VMessageBox::Quit|VMessageBox::Default);
00096 if (ret != VMessageBox::Continue) {
00097
00098 vError("Exiting duplicate Vidalia process.");
00099 return 1;
00100 }
00101 }
00102 write_pidfile(pidfile);
00103
00104
00105
00106
00107
00108 Vidalia::setQuitOnLastWindowClosed(false);
00109
00110
00111 MainWindow mainWin;
00112
00113
00114 int ret = vidalia.run();
00115
00116
00117 QFile::remove(pidfile);
00118 vNotice("Vidalia is exiting cleanly (return code %1).").arg(ret);
00119 return ret;
00120 }
00121