~ubuntu-branches/ubuntu/quantal/akonadi/quantal

« back to all changes in this revision

Viewing changes to shared/akapplication.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2012-01-24 23:43:13 UTC
  • mto: (3.1.12 sid)
  • mto: This revision was merged to the branch mainline in revision 69.
  • Revision ID: package-import@ubuntu.com-20120124234313-ooald4uh9w8jilyw
Tags: upstream-1.7.0
ImportĀ upstreamĀ versionĀ 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#ifndef AKAPPLICATION_H
21
21
#define AKAPPLICATION_H
22
22
 
23
 
#include <QtCore/QCoreApplication>
 
23
#include <QtCore/QObject>
24
24
 
25
25
#ifndef _WIN32_WCE
26
26
#include <boost/program_options.hpp>
27
27
#endif
28
28
 
 
29
class QCoreApplication;
 
30
class QApplication;
 
31
 
29
32
/**
30
33
 * D-Bus session bus monitoring and command line handling.
31
34
 */
32
 
class AkApplication : public QCoreApplication
 
35
class AkApplication : public QObject
33
36
{
34
37
  Q_OBJECT
35
38
  public:
36
 
    AkApplication( int & argc, char ** argv );
37
39
    void parseCommandLine();
38
40
    void setDescription( const QString &desc ) { mDescription = desc; }
39
41
 
41
43
    void addCommandLineOptions( const boost::program_options::options_description &desc );
42
44
    const boost::program_options::variables_map& commandLineArguments() const { return mCmdLineArguments; }
43
45
#endif
44
 
    
 
46
 
45
47
    void printUsage() const;
46
48
 
 
49
    /** Returns the instance identifier when running in multi-instance mode, empty string otherwise. */
 
50
    static QString instanceIdentifier();
 
51
 
 
52
    /** Returns @c true if we run in multi-instance mode. */
 
53
    static bool hasInstanceIdentifier();
 
54
 
 
55
    /** Forward to Q[Core]Application for convenience. */
 
56
    int exec();
 
57
 
 
58
  protected:
 
59
    AkApplication( int & argc, char ** argv );
 
60
    void init();
 
61
    QScopedPointer<QCoreApplication> mApp;
 
62
 
 
63
  private:
 
64
    /** Change instane identifier, for unit tests only. */
 
65
    static void setInstanceIdentifier( const QString& instanceId );
 
66
    friend void akTestSetInstanceIdentifier(const QString&);
 
67
 
47
68
  private slots:
48
69
    void pollSessionBus() const;
49
70
 
51
72
    int mArgc;
52
73
    char **mArgv;
53
74
    QString mDescription;
 
75
    QString mInstanceId;
 
76
    static AkApplication* sInstance;
54
77
 
55
78
#ifndef _WIN32_WCE
56
79
    boost::program_options::options_description mCmdLineOptions;
58
81
#endif
59
82
};
60
83
 
 
84
template <typename T>
 
85
class AkApplicationImpl : public AkApplication
 
86
{
 
87
  public:
 
88
    AkApplicationImpl( int &argc, char ** argv ) : AkApplication( argc, argv )
 
89
    {
 
90
      mApp.reset( new T( argc, argv ) );
 
91
      init();
 
92
    }
 
93
};
 
94
 
 
95
typedef AkApplicationImpl<QCoreApplication> AkCoreApplication;
 
96
typedef AkApplicationImpl<QApplication> AkGuiApplication;
 
97
 
61
98
#endif