~ubuntu-branches/ubuntu/raring/gwibber/raring-proposed

« back to all changes in this revision

Viewing changes to src/friends-application.cpp

  • Committer: Package Import Robot
  • Author(s): Ken VanDine
  • Date: 2013-04-03 01:03:12 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20130403010312-vtjegq0c7ogvm83e
Tags: 3.7.0bzr13.04.02-0ubuntu1
* Ported to use Friends (LP: #1156979)
* New icons from Armando Lara
* debian/control
  - added transitional packages for gwibber-* to friends-*

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 Canonical, Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
#include "friends-application.h"
 
18
#include <QtQuick/QQuickView>
 
19
#include <QtGui/QGuiApplication>
 
20
#include <QtQml/QQmlEngine>
 
21
#include <QtQml>
 
22
#include <QtQuick/QQuickItem>
 
23
#include <QtCore/QCoreApplication>
 
24
 
 
25
static void printUsage(const QStringList& arguments)
 
26
{
 
27
    qDebug() << "usage:"
 
28
             << arguments.at(0).toUtf8().constData()
 
29
             << "[-testability] [--fullscreen]";
 
30
}
 
31
 
 
32
FriendsApplication::FriendsApplication(int &argc, char **argv)
 
33
    : QGuiApplication(argc, argv), m_view(0)
 
34
{
 
35
    // The testability driver is only loaded by QApplication but not by QGuiApplication.
 
36
    // However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
 
37
    if (arguments().contains(QLatin1String("-testability"))) {
 
38
        QLibrary testLib(QLatin1String("qttestability"));
 
39
        if (testLib.load()) {
 
40
            typedef void (*TasInitialize)(void);
 
41
            TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
 
42
            if (initFunction) {
 
43
                initFunction();
 
44
            } else {
 
45
                qCritical("Library qttestability resolve failed!");
 
46
            }
 
47
        } else {
 
48
            qCritical("Library qttestability load failed!");
 
49
        }
 
50
    }
 
51
}
 
52
 
 
53
inline bool isRunningInstalled() {
 
54
    static bool installed = (QCoreApplication::applicationDirPath() ==
 
55
                             QDir(("/usr/bin")).canonicalPath());
 
56
    return installed;
 
57
}
 
58
 
 
59
inline QString getAppDirectory() {
 
60
    if (isRunningInstalled()) {
 
61
        return QString("/usr/share/friends-app/qml/");
 
62
    } else {
 
63
        return QString(QCoreApplication::applicationDirPath() + "/../qml/");
 
64
    }
 
65
}
 
66
 
 
67
bool FriendsApplication::setup()
 
68
{
 
69
    FriendsApplication::setApplicationName("Friends");
 
70
    QQuickView* m_view = new QQuickView();
 
71
 
 
72
    m_view->setResizeMode(QQuickView::SizeRootObjectToView);
 
73
    m_view->setTitle("Friends");
 
74
    m_view->engine()->setBaseUrl(QUrl::fromLocalFile(getAppDirectory()));
 
75
    QObject::connect(m_view->engine(), SIGNAL(quit()), qApp, SLOT(quit()));
 
76
    m_view->setSource(QUrl::fromLocalFile("friends-app.qml"));
 
77
    m_view->setColor("transparent");
 
78
    connect(m_view->engine(), SIGNAL(quit()), SLOT(quit()));
 
79
    if (arguments().contains(QLatin1String("--fullscreen"))) m_view->showFullScreen();
 
80
    else m_view->show();
 
81
 
 
82
    return true;
 
83
}
 
84
 
 
85
FriendsApplication::~FriendsApplication()
 
86
{
 
87
    if (m_view) {
 
88
        delete m_view;
 
89
    }
 
90
}