vidalia.h

Go to the documentation of this file.
00001 /****************************************************************
00002  *  Vidalia is distributed under the following license:
00003  *
00004  *  Copyright (C) 2006,  Matt Edman, Justin Hipple
00005  *
00006  *  This program is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU General Public License
00008  *  as published by the Free Software Foundation; either version 2
00009  *  of the License, or (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  *  Boston, MA  02110-1301, USA.
00020  ****************************************************************/
00021 
00022 /**
00023  * \file vidalia.h
00024  * \version $Id: vidalia.h 1883 2007-08-26 05:35:08Z edmanm $
00025  * \brief Main Vidalia QApplication object
00026  */
00027 
00028 #ifndef _VIDALIA_H
00029 #define _VIDALIA_H
00030 
00031 #if defined(Q_OS_WIN)
00032 #include <windows.h>
00033 #include <util/win32.h>
00034 #endif
00035 
00036 #include <QApplication>
00037 #include <QMap>
00038 #include <QString>
00039 
00040 #include <util/log.h>
00041 #include <gui/help/browser/helpbrowser.h>
00042 #include <config/vidaliasettings.h>
00043 #include <control/torcontrol.h>
00044 
00045 /** Vidalia's version string */
00046 #define VIDALIA_VERSION    "0.0.14"
00047 
00048 /** Pointer to this Vidalia application instance. */
00049 #define vApp  ((Vidalia *)qApp)
00050 
00051 #define vDebug(fmt)   (vApp->log(Log::Debug, (fmt)))
00052 #define vInfo(fmt)    (vApp->log(Log::Info, (fmt)))
00053 #define vNotice(fmt)  (vApp->log(Log::Notice, (fmt)))
00054 #define vWarn(fmt)    (vApp->log(Log::Warn, (fmt)))
00055 #define vError(fmt)   (vApp->log(Log::Error, (fmt)))
00056 
00057 
00058 class Vidalia : public QApplication
00059 {
00060   Q_OBJECT
00061 
00062 public:
00063   /** Constructor. */
00064   Vidalia(QStringList args, int &argc, char **argv);
00065   /** Destructor. */
00066   ~Vidalia();
00067 
00068   /** Return the map of command-line arguments and values. */
00069   static QMap<QString, QString> arguments() { return _args; }
00070   /** Validates that all arguments were well-formed. */
00071   static bool validateArguments(QString &errmsg);
00072   /** Displays usage information for command-line args. */
00073   static void showUsageMessageBox();
00074   /** Returns true if the user wants to see usage information. */
00075   static bool showUsage();
00076   
00077   /** Sets the current language. */
00078   static bool setLanguage(QString languageCode = QString());
00079   /** Sets the current GUI style. */
00080   static bool setStyle(QString styleKey = QString());
00081   
00082   /** Returns the current language. */
00083   static QString language() { return _language; }
00084   /** Returns the current GUI style. */
00085   static QString style() { return _style; }
00086   /** Returns Vidalia's application version. */
00087   static QString version() { return VIDALIA_VERSION; }
00088 
00089   /** Returns Vidalia's main TorControl object. */
00090   static TorControl* torControl() { return _torControl; }
00091   
00092   /** Returns the location Vidalia uses for its data files. */
00093   static QString dataDirectory();
00094   /** Returns the default location of Vidalia's data directory. */
00095   static QString defaultDataDirectory();
00096   
00097   /** Returns the location of Vidalia's pid file. */
00098   static QString pidFile();
00099 
00100   /** Writes <b>msg</b> with severity <b>level</b> to Vidalia's log. */
00101   static Log::LogMessage log(Log::LogLevel level, QString msg);
00102 
00103 public slots:
00104   /** Shows the specified help topic, or the default if empty. */
00105   static void help(QString topic = QString());
00106 
00107 signals:
00108   /** Signals that the application needs to shutdown now. */
00109   void shutdown();
00110 
00111 protected:
00112 #if defined(Q_OS_WIN)
00113   /** Filters Windows events, looking for events of interest */
00114   bool winEventFilter(MSG *msg, long *result);
00115 #endif
00116 
00117 private:
00118   /** Catches debugging messages from Qt and sends them to 
00119    * Vidalia's logs. */
00120   static void qt_msg_handler(QtMsgType type, const char *msg);
00121 
00122   /** Parse the list of command-line arguments. */
00123   void parseArguments(QStringList args);
00124   /** Returns true if the specified arguments wants a value. */
00125   bool argNeedsValue(QString argName);
00126 
00127   static QMap<QString, QString> _args; /**< List of command-line arguments.  */
00128   static QString _style;               /**< The current GUI style.           */
00129   static QString _language;            /**< The current language.            */
00130 
00131   static TorControl* _torControl;      /**< Vidalia's main TorControl object.*/
00132   static HelpBrowser* _help;           /**< Vidalia's configurable settings. */
00133   
00134   static Log _log; /**< Logs debugging messages to file or stdout. */
00135 };
00136 
00137 #endif
00138 

Generated on Wed Sep 5 15:49:28 2007 for Vidalia by  doxygen 1.5.3