vidalia.h

Go to the documentation of this file.
00001 /*
00002 **  This file is part of Vidalia, and is subject to the license terms in the
00003 **  LICENSE file, found in the top level directory of this distribution. If you
00004 **  did not receive the LICENSE file with this file, you may obtain it from the
00005 **  Vidalia source package distributed by the Vidalia Project at
00006 **  http://www.vidalia-project.net/. No part of Vidalia, including this file,
00007 **  may be copied, modified, propagated, or distributed except according to the
00008 **  terms described in the LICENSE file.
00009 */
00010 
00011 /*
00012 ** \file vidalia.h
00013 ** \version $Id: vidalia.h 2981 2008-08-17 05:49:08Z edmanm $
00014 ** \brief Main Vidalia QApplication object
00015 */
00016 
00017 #ifndef _VIDALIA_H
00018 #define _VIDALIA_H
00019 
00020 #if defined(Q_OS_WIN)
00021 #include <windows.h>
00022 #include <win32.h>
00023 #endif
00024 
00025 #include <QApplication>
00026 #include <QMap>
00027 #include <QString>
00028 #include <QKeySequence>
00029 
00030 #include <log.h>
00031 #include <vidaliasettings.h>
00032 #include <torcontrol.h>
00033 
00034 #include "config.h"
00035 
00036 /** Pointer to this Vidalia application instance. */
00037 #define vApp  ((Vidalia *)qApp)
00038 
00039 #define vDebug(fmt)   (vApp->log(Log::Debug, (fmt)))
00040 #define vInfo(fmt)    (vApp->log(Log::Info, (fmt)))
00041 #define vNotice(fmt)  (vApp->log(Log::Notice, (fmt)))
00042 #define vWarn(fmt)    (vApp->log(Log::Warn, (fmt)))
00043 #define vError(fmt)   (vApp->log(Log::Error, (fmt)))
00044 
00045 
00046 class Vidalia : public QApplication
00047 {
00048   Q_OBJECT
00049 
00050 public:
00051   /** Constructor. */
00052   Vidalia(QStringList args, int &argc, char **argv);
00053   /** Destructor. */
00054   ~Vidalia();
00055 
00056   /** Return the map of command-line arguments and values. */
00057   static QMap<QString, QString> arguments() { return _args; }
00058   /** Validates that all arguments were well-formed. */
00059   static bool validateArguments(QString &errmsg);
00060   /** Displays usage information for command-line args. */
00061   static void showUsageMessageBox();
00062   /** Returns true if the user wants to see usage information. */
00063   static bool showUsage();
00064   
00065   /** Sets the current language. */
00066   static bool setLanguage(QString languageCode = QString());
00067   /** Sets the current GUI style. */
00068   static bool setStyle(QString styleKey = QString());
00069   
00070   /** Returns the current language. */
00071   static QString language() { return _language; }
00072   /** Returns the current GUI style. */
00073   static QString style() { return _style; }
00074   /** Returns Vidalia's application version. */
00075   static QString version() { return VIDALIA_VERSION; }
00076 
00077   /** Returns Vidalia's main TorControl object. */
00078   static TorControl* torControl() { return _torControl; }
00079   
00080   /** Returns the location Vidalia uses for its data files. */
00081   static QString dataDirectory();
00082   /** Returns the default location of Vidalia's data directory. */
00083   static QString defaultDataDirectory();
00084   
00085   /** Returns the location of Vidalia's pid file. */
00086   static QString pidFile();
00087 
00088   /** Writes <b>msg</b> with severity <b>level</b> to Vidalia's log. */
00089   static Log::LogMessage log(Log::LogLevel level, QString msg);
00090  
00091   /** Enters the main event loop and waits until exit() is called. The signal
00092    * running() will be emitted when the event loop has started. */
00093   static int run();
00094 
00095   /** Creates and binds a shortcut such that when <b>key</b> is pressed in
00096    * <b>sender</b>'s context, <b>receiver</b>'s <b>slot</b> will be called. */
00097   static void createShortcut(const QKeySequence &key, QWidget *sender,
00098                              QObject *receiver, const char *slot);
00099 
00100   /** Creates and binds a shortcut such that when <b>key</b> is pressed in
00101    * <b>sender</b>'s context, <b>receiver</b>'s <b>slot</b> will be called. */
00102   static void createShortcut(const QString &key, QWidget *sender,
00103                              QObject *receiver, const char *slot);
00104 
00105 signals:
00106   /** Emitted when the application is running and the main event loop has
00107    * started. */ 
00108   void running();
00109   /** Signals that the application needs to shutdown now. */
00110   void shutdown();
00111 
00112 protected:
00113 #if defined(Q_OS_WIN)
00114   /** Filters Windows events, looking for events of interest */
00115   bool winEventFilter(MSG *msg, long *result);
00116 #endif
00117 
00118 private slots:
00119   /** Called when the application's main event loop has started. This method
00120    * will emit the running() signal to indicate that the application's event
00121    * loop is running. */
00122   void onEventLoopStarted();
00123   
00124 private:
00125   /** Catches debugging messages from Qt and sends them to 
00126    * Vidalia's logs. */
00127   static void qt_msg_handler(QtMsgType type, const char *msg);
00128 
00129   /** Parse the list of command-line arguments. */
00130   void parseArguments(QStringList args);
00131   /** Returns true if the specified arguments wants a value. */
00132   bool argNeedsValue(QString argName);
00133 
00134   static QMap<QString, QString> _args; /**< List of command-line arguments.  */
00135   static QString _style;               /**< The current GUI style.           */
00136   static QString _language;            /**< The current language.            */
00137   static TorControl* _torControl;      /**< Vidalia's main TorControl object.*/
00138   static Log _log; /**< Logs debugging messages to file or stdout. */
00139 };
00140 
00141 #endif
00142 

Generated on Tue Jul 7 16:58:27 2009 for Vidalia by  doxygen 1.4.7