2007-11-14 22:18:48 -05:00
|
|
|
/****************************************************************
|
2009-12-14 12:13:10 -05:00
|
|
|
* This file is distributed under the following license:
|
|
|
|
*
|
|
|
|
* Copyright (c) 2006-2007, crypton
|
2007-12-08 06:27:01 -05:00
|
|
|
* Copyright (c) 2006, Matt Edman, Justin Hipple
|
2007-11-14 22:18:48 -05:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2007-12-08 06:27:01 -05:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
2007-11-14 22:18:48 -05:00
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
****************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _RSHARE_H
|
|
|
|
#define _RSHARE_H
|
|
|
|
|
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
#include <windows.h>
|
|
|
|
#include <util/win32.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QString>
|
2008-08-15 16:07:54 -04:00
|
|
|
#include <QKeySequence>
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-08-15 13:49:57 -04:00
|
|
|
#include "util/log.h"
|
2014-03-17 16:56:06 -04:00
|
|
|
#include "retroshare/rstypes.h"
|
2008-08-14 20:23:27 -04:00
|
|
|
|
2008-08-15 13:49:57 -04:00
|
|
|
/** Pointer to this RetroShare application instance. */
|
|
|
|
#define rApp ((Rshare *)qApp)
|
|
|
|
|
|
|
|
#define rDebug(fmt) (rApp->log(Log::Debug, (fmt)))
|
|
|
|
#define rInfo(fmt) (rApp->log(Log::Info, (fmt)))
|
|
|
|
#define rNotice(fmt) (rApp->log(Log::Notice, (fmt)))
|
|
|
|
#define rWarn(fmt) (rApp->log(Log::Warn, (fmt)))
|
|
|
|
#define rError(fmt) (rApp->log(Log::Error, (fmt)))
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
class Rshare : public QApplication
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
/** Constructor. */
|
2012-09-01 07:40:54 -04:00
|
|
|
Rshare(QStringList args, int &argc, char **argv, const QString &dir);
|
2007-11-14 22:18:48 -05:00
|
|
|
/** Destructor. */
|
|
|
|
~Rshare();
|
|
|
|
|
2015-01-14 18:26:51 -05:00
|
|
|
/** Return the version info */
|
2015-03-08 09:31:44 -04:00
|
|
|
static QString retroshareVersion(bool withRevision);
|
2015-01-14 18:26:51 -05:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/** Return the map of command-line arguments and values. */
|
|
|
|
static QMap<QString, QString> arguments() { return _args; }
|
|
|
|
/** Validates that all arguments were well-formed. */
|
|
|
|
bool validateArguments(QString &errmsg);
|
|
|
|
/** Prints usage information to the given text stream. */
|
2008-08-15 13:49:57 -04:00
|
|
|
//void printUsage(QString errmsg = QString());
|
|
|
|
/** Displays usage information for command-line args. */
|
|
|
|
static void showUsageMessageBox();
|
|
|
|
/** Returns true if the user wants to see usage information. */
|
|
|
|
static bool showUsage();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/** Sets the current language. */
|
|
|
|
static bool setLanguage(QString languageCode = QString());
|
2012-11-10 13:59:58 -05:00
|
|
|
/** Sets the current locale. */
|
|
|
|
static bool setLocale(QString languageCode = QString());
|
2012-11-15 16:35:37 -05:00
|
|
|
/** Get custom date format (defaultlongformat) */
|
|
|
|
static QString customDateFormat();
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/** Sets the current GUI style. */
|
|
|
|
static bool setStyle(QString styleKey = QString());
|
2012-05-02 16:19:51 -04:00
|
|
|
/** Sets the current GUI stylesheet. */
|
2008-01-16 03:12:16 -05:00
|
|
|
static bool setSheet(QString sheet = QString());
|
2012-05-02 16:19:51 -04:00
|
|
|
/** Loads stylesheet from external file **/
|
|
|
|
static void loadStyleSheet(const QString &sheetName);
|
2012-08-24 19:35:57 -04:00
|
|
|
/** get list of available stylesheets **/
|
|
|
|
static void getAvailableStyleSheets(QMap<QString, QString> &styleSheets);
|
2012-05-19 18:18:15 -04:00
|
|
|
/** Recalculates matching stylesheet for widget **/
|
|
|
|
static void refreshStyleSheet(QWidget *widget, bool processChildren);
|
2008-08-15 15:03:50 -04:00
|
|
|
|
2014-03-17 16:56:06 -04:00
|
|
|
static bool loadCertificate(const RsPeerId &accountId, bool autoLogin);
|
2012-10-31 21:07:36 -04:00
|
|
|
|
2011-10-14 17:16:34 -04:00
|
|
|
/**
|
|
|
|
* Update Language, Style and StyleSheet.
|
|
|
|
* First args are cheked for a style then the settings.
|
|
|
|
*/
|
|
|
|
static void resetLanguageAndStyle();
|
|
|
|
|
2011-11-17 16:17:24 -05:00
|
|
|
/** Initialize plugins. */
|
|
|
|
static void initPlugins();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/** Returns the current language. */
|
|
|
|
static QString language() { return _language; }
|
|
|
|
/** Returns the current GUI style. */
|
|
|
|
static QString style() { return _style; }
|
2008-01-16 03:12:16 -05:00
|
|
|
/** Returns the current GUI stylesheet. */
|
|
|
|
static QString stylesheet() { return _stylesheet; }
|
2013-04-22 17:12:38 -04:00
|
|
|
/** Returns Rshare's application startup time. */
|
|
|
|
static QDateTime startupTime();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
/** Returns the location Rshare uses for its data files. */
|
|
|
|
static QString dataDirectory();
|
|
|
|
/** Returns the default location of Rshare's data directory. */
|
|
|
|
static QString defaultDataDirectory();
|
|
|
|
/** Creates Rshare's data directory, if it doesn't already exist. */
|
|
|
|
static bool createDataDirectory(QString *errmsg);
|
|
|
|
|
2008-08-15 13:49:57 -04:00
|
|
|
/** Writes <b>msg</b> with severity <b>level</b> to RetroShare's log. */
|
|
|
|
static Log::LogMessage log(Log::LogLevel level, QString msg);
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/** Creates Rshare's data directory, if it doesn't already exist. */
|
|
|
|
static bool setConfigDirectory(QString dir);
|
|
|
|
|
2008-08-15 13:49:57 -04:00
|
|
|
/** Enters the main event loop and waits until exit() is called. The signal
|
|
|
|
* running() will be emitted when the event loop has started. */
|
|
|
|
static int run();
|
|
|
|
|
2008-08-15 16:07:54 -04:00
|
|
|
/** Creates and binds a shortcut such that when <b>key</b> is pressed in
|
|
|
|
* <b>sender</b>'s context, <b>receiver</b>'s <b>slot</b> will be called. */
|
|
|
|
static void createShortcut(const QKeySequence &key, QWidget *sender,
|
|
|
|
QWidget *receiver, const char *slot);
|
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
signals:
|
2008-08-15 13:49:57 -04:00
|
|
|
/** Emitted when the application is running and the main event loop has
|
|
|
|
* started. */
|
|
|
|
void running();
|
2007-11-14 22:18:48 -05:00
|
|
|
/** Signals that the application needs to shutdown now. */
|
|
|
|
void shutdown();
|
2012-10-25 14:06:33 -04:00
|
|
|
/** Global blink timer */
|
|
|
|
void blink(bool on);
|
2013-03-17 12:31:30 -04:00
|
|
|
/** Global timer every second */
|
|
|
|
void secondTick();
|
2015-03-09 16:41:14 -04:00
|
|
|
/** Global timer every minute */
|
|
|
|
void minuteTick();
|
2007-11-14 22:18:48 -05:00
|
|
|
|
2008-08-15 13:49:57 -04:00
|
|
|
private slots:
|
|
|
|
/** Called when the application's main event loop has started. This method
|
|
|
|
* will emit the running() signal to indicate that the application's event
|
|
|
|
* loop is running. */
|
|
|
|
void onEventLoopStarted();
|
2012-10-25 14:06:33 -04:00
|
|
|
void blinkTimer();
|
2008-08-15 13:49:57 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
private:
|
2012-11-10 13:59:58 -05:00
|
|
|
/** customize the date format (defaultlongformat) */
|
|
|
|
static void customizeDateFormat();
|
2008-08-15 13:49:57 -04:00
|
|
|
|
2007-11-14 22:18:48 -05:00
|
|
|
/** Parse the list of command-line arguments. */
|
|
|
|
void parseArguments(QStringList args);
|
|
|
|
/** Returns true if the specified arguments wants a value. */
|
|
|
|
bool argNeedsValue(QString argName);
|
|
|
|
|
|
|
|
static QMap<QString, QString> _args; /**< List of command-line arguments. */
|
|
|
|
static QString _style; /**< The current GUI style. */
|
2008-08-15 13:49:57 -04:00
|
|
|
static QString _stylesheet; /**< The current GUI stylesheet. */
|
2007-11-14 22:18:48 -05:00
|
|
|
static QString _language; /**< The current language. */
|
2012-11-15 16:35:37 -05:00
|
|
|
static QString _dateformat; /**< The format for dates in feed items etc. */
|
2008-08-15 13:49:57 -04:00
|
|
|
static Log _log; /**< Logs debugging messages to file or stdout. */
|
2013-04-22 17:12:38 -04:00
|
|
|
static QDateTime mStartupTime; // startup time
|
2007-11-14 22:18:48 -05:00
|
|
|
|
|
|
|
static bool useConfigDir;
|
|
|
|
static QString configDir;
|
2012-10-25 14:06:33 -04:00
|
|
|
bool mBlink;
|
2007-11-14 22:18:48 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|