~timo-jyrinki/ubuntu/trusty/maliit-framework/fix_qt52

« back to all changes in this revision

Viewing changes to connection/connectionfactory.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:
14
14
 
15
15
#include "connectionfactory.h"
16
16
 
17
 
#ifndef MALIIT_DISABLE_DBUS
18
 
#ifdef HAVE_GLIB_DBUS
19
 
#include "glibdbusimserverproxy.h"
20
 
#include "minputcontextglibdbusconnection.h"
21
 
#else
22
 
#include "dbusserverconnection.h"
23
17
#include "dbusinputcontextconnection.h"
24
 
#endif
25
 
#endif
26
 
#include "mimdirectserverconnection.h"
27
18
 
28
19
#ifdef HAVE_WAYLAND
29
 
#include "minputcontextwestonimprotocolconnection.h"
 
20
#include "waylandinputmethodconnection.h"
30
21
#endif
31
22
 
32
23
namespace Maliit {
33
 
#ifndef MALIIT_DISABLE_DBUS
34
24
namespace DBus {
35
25
 
36
 
MImServerConnection *createServerConnectionWithDynamicAddress()
37
 
{
38
 
    const QSharedPointer<Maliit::InputContext::DBus::Address> address(new Maliit::InputContext::DBus::DynamicAddress);
39
 
#ifdef HAVE_GLIB_DBUS
40
 
    return new GlibDBusIMServerProxy(address);
41
 
#else
42
 
    return new DBusServerConnection(address);
43
 
#endif
44
 
}
45
 
 
46
 
MImServerConnection *createServerConnectionWithFixedAddress(const QString &fixedAddress)
47
 
{
48
 
    const QSharedPointer<Maliit::InputContext::DBus::Address> address(new Maliit::InputContext::DBus::FixedAddress(fixedAddress));
49
 
#ifdef HAVE_GLIB_DBUS
50
 
    return new GlibDBusIMServerProxy(address);
51
 
#else
52
 
    return new DBusServerConnection(address);
53
 
#endif
54
 
}
55
 
 
56
26
MInputContextConnection *createInputContextConnectionWithDynamicAddress()
57
27
{
58
 
#ifdef HAVE_GLIB_DBUS
59
 
    std::tr1::shared_ptr<Maliit::Server::DBus::Address> address(new Maliit::Server::DBus::DynamicAddress);
60
 
    return new MInputContextGlibDBusConnection(address, false);
61
 
#else
62
28
    QSharedPointer<Maliit::Server::DBus::Address> address(new Maliit::Server::DBus::DynamicAddress);
63
29
    return new DBusInputContextConnection(address);
64
 
#endif
65
30
}
66
31
 
67
32
MInputContextConnection *createInputContextConnectionWithFixedAddress(const QString &fixedAddress, bool allowAnonymous)
68
33
{
69
 
#ifdef HAVE_GLIB_DBUS
70
 
    std::tr1::shared_ptr<Maliit::Server::DBus::Address> address(new Maliit::Server::DBus::FixedAddress(fixedAddress));
71
 
    return new MInputContextGlibDBusConnection(address, allowAnonymous);
72
 
#else
73
34
    Q_UNUSED(allowAnonymous);
74
35
    QSharedPointer<Maliit::Server::DBus::Address> address(new Maliit::Server::DBus::FixedAddress(fixedAddress));
75
36
    return new DBusInputContextConnection(address);
76
 
#endif
77
37
}
78
38
 
79
39
} // namespace DBus
80
 
#endif // MALIIT_DISABLE_DBUS
81
40
 
82
41
#ifdef HAVE_WAYLAND
83
42
MInputContextConnection *createWestonIMProtocolConnection()
84
43
{
85
 
    return new MInputContextWestonIMProtocolConnection;
86
 
}
87
 
#endif
88
 
 
89
 
QSharedPointer<MImServerConnection> createServerConnection(const QString &connectionType)
90
 
{
91
 
    typedef QSharedPointer<MImServerConnection> ConnectionPtr;
92
 
    static QWeakPointer<MImServerConnection> cached_connection;
93
 
 
94
 
    if (ConnectionPtr connection = cached_connection.toStrongRef()) {
95
 
        return connection;
96
 
    }
97
 
 
98
 
    if (connectionType.isEmpty()) {
99
 
        qCritical() << "Empty connection type name. Refusing to connect to Maliit server."
100
 
                    << "\nHave you checked the environment variables for loading input method"
101
 
                    << "modules ([QT|GTK]_IM_MODULE)?";
102
 
        return ConnectionPtr();
103
 
    }
104
 
 
105
 
    if (connectionType == MALIIT_INPUTCONTEXT_NAME) {
106
 
#ifndef MALIIT_DISABLE_DBUS
107
 
        const QByteArray overriddenAddress = qgetenv("MALIIT_SERVER_ADDRESS");
108
 
        ConnectionPtr connection = ConnectionPtr(overriddenAddress.isEmpty()
109
 
                                                 ? Maliit::DBus::createServerConnectionWithDynamicAddress()
110
 
                                                 : Maliit::DBus::createServerConnectionWithFixedAddress(overriddenAddress));
111
 
        cached_connection = connection;
112
 
 
113
 
        return connection;
114
 
#else
115
 
        qCritical("This connection type to Maliit server is not available since DBus support is disabled");
116
 
#endif
117
 
    } else if (connectionType == MALIIT_INPUTCONTEXT_NAME"Direct") {
118
 
        ConnectionPtr connection(new MImDirectServerConnection);
119
 
 
120
 
        cached_connection = connection;
121
 
 
122
 
        return connection;
123
 
    } else {
124
 
        qCritical() << __PRETTY_FUNCTION__
125
 
                    << "Invalid connection type (" + connectionType + "),"
126
 
                    << "unable to create connection to Maliit server";
127
 
        return ConnectionPtr();
128
 
    }
129
 
}
 
44
    return new WaylandInputMethodConnection;
 
45
}
 
46
#endif
130
47
 
131
48
} // namespace Maliit