~michael-sheldon/ubuntu/utopic/maliit-framework/fix-orientation-updates

« back to all changes in this revision

Viewing changes to .pc/0002-ubuntu_session_type.patch/passthroughserver/main.cpp

  • Committer: Package Import Robot
  • Author(s): Ricardo Salveti de Araujo, Sergio Schvezov, Ricardo Salveti de Araujo
  • Date: 2013-07-23 19:47:04 UTC
  • mfrom: (1.1.2) (1.2.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130723194704-1lsy1kmlda069cea
Tags: 0.99.0+git20130615+97e8335-0ubuntu1
[ Sergio Schvezov ]
* New build from HEAD 97e8335.
* Packaging import from lp:phablet-extras/maliit-framework.

[ Ricardo Salveti de Araujo ]
* debian/control: adding vcs and fixing dependencies
* General package cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* * This file is part of Maliit framework *
 
2
 *
 
3
 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 
4
 * All rights reserved.
 
5
 *
 
6
 * Contact: maliit-discuss@lists.maliit.org
 
7
 *
 
8
 * This library is free software; you can redistribute it and/or
 
9
 * modify it under the terms of the GNU Lesser General Public
 
10
 * License version 2.1 as published by the Free Software Foundation
 
11
 * and appearing in the file LICENSE.LGPL included in the packaging
 
12
 * of this file.
 
13
 */
 
14
 
 
15
#include <QtGlobal>
 
16
 
 
17
#include "connectionfactory.h"
 
18
#include "mimserver.h"
 
19
#include "mimserveroptions.h"
 
20
#ifndef NOXCB
 
21
#include "xcbplatform.h"
 
22
#endif
 
23
#ifdef HAVE_WAYLAND
 
24
#include "waylandplatform.h"
 
25
#endif // HAVE_WAYLAND
 
26
#include "unknownplatform.h"
 
27
 
 
28
#include <QGuiApplication>
 
29
#include <QtDebug>
 
30
 
 
31
namespace {
 
32
 
 
33
void disableMInputContextPlugin()
 
34
{
 
35
    // none is a special value for QT_IM_MODULE, which disables loading of any
 
36
    // input method module in Qt 5.
 
37
    setenv("QT_IM_MODULE", "none", true);
 
38
}
 
39
 
 
40
bool isDebugEnabled()
 
41
{
 
42
    static int debugEnabled = -1;
 
43
 
 
44
    if (debugEnabled == -1) {
 
45
        QByteArray debugEnvVar = qgetenv("MALIIT_DEBUG");
 
46
        if (!debugEnvVar.isEmpty() && debugEnvVar != "0") {
 
47
            debugEnabled = 1;
 
48
        } else {
 
49
            debugEnabled = 0;
 
50
        }
 
51
    }
 
52
 
 
53
    return debugEnabled == 1;
 
54
}
 
55
 
 
56
void outputMessagesToStdErr(QtMsgType type,
 
57
                            const QMessageLogContext &context,
 
58
                            const QString &msg)
 
59
{
 
60
    Q_UNUSED(context);
 
61
    QByteArray utf_text(msg.toUtf8());
 
62
    const char *raw(utf_text.constData());
 
63
 
 
64
    switch (type) {
 
65
    case QtDebugMsg:
 
66
        if (isDebugEnabled()) {
 
67
            fprintf(stderr, "DEBUG: %s\n", raw);
 
68
        }
 
69
        break;
 
70
    case QtWarningMsg:
 
71
        fprintf(stderr, "WARNING: %s\n", raw);
 
72
        break;
 
73
    case QtCriticalMsg:
 
74
        fprintf(stderr, "CRITICAL: %s\n", raw);
 
75
        break;
 
76
    case QtFatalMsg:
 
77
        fprintf(stderr, "FATAL: %s\n", raw);
 
78
        abort();
 
79
    }
 
80
}
 
81
 
 
82
QSharedPointer<MInputContextConnection> createConnection(const MImServerConnectionOptions &options)
 
83
{
 
84
#ifdef HAVE_WAYLAND
 
85
    if (QGuiApplication::platformName().startsWith("wayland")) {
 
86
        return QSharedPointer<MInputContextConnection>(Maliit::createWestonIMProtocolConnection());
 
87
    } else
 
88
#endif
 
89
    if (options.overriddenAddress.isEmpty()) {
 
90
        return QSharedPointer<MInputContextConnection>(Maliit::DBus::createInputContextConnectionWithDynamicAddress());
 
91
    } else {
 
92
        return QSharedPointer<MInputContextConnection>(Maliit::DBus::createInputContextConnectionWithFixedAddress(options.overriddenAddress,
 
93
                                                                                                                  options.allowAnonymous));
 
94
    }
 
95
}
 
96
 
 
97
QSharedPointer<Maliit::AbstractPlatform> createPlatform()
 
98
{
 
99
#ifdef HAVE_WAYLAND
 
100
    if (QGuiApplication::platformName().startsWith("wayland")) {
 
101
        return QSharedPointer<Maliit::AbstractPlatform>(new Maliit::WaylandPlatform);
 
102
    } else
 
103
#endif
 
104
#ifndef NOXCB
 
105
    if (QGuiApplication::platformName() == "xcb") {
 
106
        return QSharedPointer<Maliit::AbstractPlatform>(new Maliit::XCBPlatform);
 
107
    } else {
 
108
#else
 
109
    {
 
110
#endif
 
111
        return QSharedPointer<Maliit::AbstractPlatform>(new Maliit::UnknownPlatform);
 
112
    }
 
113
}
 
114
 
 
115
} // unnamed namespace
 
116
 
 
117
int main(int argc, char **argv)
 
118
{
 
119
    qInstallMessageHandler(outputMessagesToStdErr);
 
120
 
 
121
    // QT_IM_MODULE, MApplication and QtMaemo5Style all try to load
 
122
    // MInputContext, which is fine for the application. For the passthrough
 
123
    // server itself, we absolutely need to prevent that.
 
124
    disableMInputContextPlugin();
 
125
 
 
126
    MImServerCommonOptions serverCommonOptions;
 
127
    MImServerConnectionOptions connectionOptions;
 
128
 
 
129
    const bool allRecognized = parseCommandLine(argc, argv);
 
130
    if (serverCommonOptions.showHelp) {
 
131
        printHelpMessage();
 
132
        return 1;
 
133
    } else if (not allRecognized) {
 
134
        printHelpMessage();
 
135
    }
 
136
 
 
137
    QGuiApplication app(argc, argv);
 
138
 
 
139
    // Input Context Connection
 
140
    QSharedPointer<MInputContextConnection> icConnection(createConnection(connectionOptions));
 
141
 
 
142
    QSharedPointer<Maliit::AbstractPlatform> platform(createPlatform());
 
143
 
 
144
    // The actual server
 
145
    MImServer::configureSettings(MImServer::PersistentSettings);
 
146
    MImServer imServer(icConnection, platform);
 
147
    Q_UNUSED(imServer);
 
148
 
 
149
    return app.exec();
 
150
}