2
* Copyright (C) 2013 Canonical, Ltd.
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.
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.
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/>.
17
#include "gwibber-application.h"
18
#include <QtQuick/QQuickView>
19
#include <QtGui/QGuiApplication>
20
#include <QtQml/QQmlEngine>
22
#include <QtQuick/QQuickItem>
23
#include <QtCore/QCoreApplication>
24
#include <dee-1.0/dee.h>
25
#include <deelistmodel.h>
28
static void printUsage(const QStringList& arguments)
31
<< arguments.at(0).toUtf8().constData()
32
<< "[-testability] [--fullscreen]";
35
GwibberApplication::GwibberApplication(int &argc, char **argv)
36
: QGuiApplication(argc, argv), m_view(0)
38
// The testability driver is only loaded by QApplication but not by QGuiApplication.
39
// However, QApplication depends on QWidget which would add some unneeded overhead => Let's load the testability driver on our own.
40
if (arguments().contains(QLatin1String("-testability"))) {
41
QLibrary testLib(QLatin1String("qttestability"));
43
typedef void (*TasInitialize)(void);
44
TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init");
48
qCritical("Library qttestability resolve failed!");
51
qCritical("Library qttestability load failed!");
56
inline bool isRunningInstalled() {
57
static bool installed = (QCoreApplication::applicationDirPath() ==
58
QDir(("/usr/bin")).canonicalPath());
62
inline QString getAppDirectory() {
63
if (isRunningInstalled()) {
64
return QString("/usr/share/gwibber-qml/qml/");
66
return QString(QCoreApplication::applicationDirPath() + "/../qml/");
71
onSynchronizedChanged(GObject* parent, GParamSpec *pspec, gpointer user_data)
73
DeeListModel *results_model = (DeeListModel*)user_data;
74
DeeModel *model = (DeeModel*)parent;
75
DeeFilter _sort_filter;
76
dee_filter_new_collator (6, &_sort_filter);
77
DeeModel* _sorted_model = dee_filter_model_new (model, &_sort_filter);
78
results_model->setModel (_sorted_model);
82
bool GwibberApplication::setup()
84
GwibberApplication::setApplicationName("Gwibber");
85
QQuickView* m_view = new QQuickView();
86
QQmlContext* context = m_view->rootContext();
87
DeeModel* _shared_model = dee_shared_model_new ("com.canonical.Friends.Streams");
88
DeeListModel *_m = new DeeListModel ();
89
context->setContextProperty("_friendsModel", _m);
90
g_signal_connect(_shared_model, "notify::synchronized", G_CALLBACK(onSynchronizedChanged), G_OBJECT(_m));
92
m_view->setResizeMode(QQuickView::SizeRootObjectToView);
93
m_view->setTitle("Gwibber");
94
m_view->engine()->setBaseUrl(QUrl::fromLocalFile(getAppDirectory()));
95
QObject::connect(m_view->engine(), SIGNAL(quit()), qApp, SLOT(quit()));
96
m_view->setSource(QUrl::fromLocalFile("GwibberApplication.qml"));
97
m_view->setColor("transparent");
98
connect(m_view->engine(), SIGNAL(quit()), SLOT(quit()));
99
if (arguments().contains(QLatin1String("--fullscreen"))) m_view->showFullScreen();
105
GwibberApplication::~GwibberApplication()