24#include "provider-plugin-process-priv.h"
26#include <Accounts/Account>
27#include <Accounts/Manager>
29#include <QCoreApplication>
32#include <QLocalSocket>
38const int cancelId = -1;
44 goToAccountsPage(false),
46 editExistingAccount(false),
50 manager =
new Accounts::Manager(
this);
53 QStringList args = QCoreApplication::arguments();
54 for (
int i = 0; i < args.length(); ++i)
56 Q_ASSERT(args[i] != NULL);
58 if (args[i] == QLatin1String(
"--create"))
60 setupType = CreateNew;
63 if (i < args.length()) {
64 account = manager->createAccount(args[i]);
67 else if (args[i] == QLatin1String(
"--edit"))
69 setupType = EditExisting;
72 if (i < args.length())
73 account = manager->account(args[i].toInt());
75 else if (args[i] == QLatin1String(
"--windowId"))
78 if (i < args.length())
79 windowId = (WId)args[i].toUInt();
80 Q_ASSERT(windowId != 0);
82 else if (args[i] == QLatin1String(
"--socketName"))
85 if (i < args.length())
87 Q_ASSERT(socketName != 0);
89 else if (args[i] == QLatin1String(
"--serviceType"))
92 if (i < args.length())
93 serviceType = args[i];
94 Q_ASSERT(serviceType != 0);
99ProviderPluginProcessPrivate::~ProviderPluginProcessPrivate()
103void ProviderPluginProcessPrivate::sendResultToCaller()
105 if (!socketName.isEmpty()) {
106 QLocalSocket *socket =
new QLocalSocket();
107 connect(socket, SIGNAL(error(QLocalSocket::LocalSocketError)),
108 this, SLOT(onSocketError(QLocalSocket::LocalSocketError)));
109 socket->connectToServer(socketName);
112 QDataStream stream(&ba, QIODevice::WriteOnly);
114 if (editExistingAccount)
115 stream << existingAccountId;
116 else if (!goToAccountsPage)
117 stream << account->id();
127 if (editExistingAccount)
128 ba = QString::number(existingAccountId).toAscii();
129 else if (!goToAccountsPage)
130 ba = QString::number(account->id()).toAscii();
132 ba = QString::number(cancelId).toAscii();
135 output.open(STDOUT_FILENO, QIODevice::WriteOnly);
136 output.write(ba.constData());
141void ProviderPluginProcessPrivate::onSocketError(QLocalSocket::LocalSocketError status)
143 qDebug() << Q_FUNC_INFO << status;
148 d_ptr(new ProviderPluginProcessPrivate(this))
150 if (plugin_instance != 0)
151 qWarning() <<
"ProviderPluginProcess already instantiated";
152 plugin_instance =
this;
155ProviderPluginProcess::~ProviderPluginProcess()
163 return plugin_instance;
181 return d->serviceType;
195 d->goToAccountsPage = value;
209 d->editExistingAccount =
true;
210 d->existingAccountId = accountId;
216 d->sendResultToCaller();
217 QCoreApplication::exit(0);
Class to manage the account provider plugins as separate processes.
QString serviceType() const
void quit()
Clean termination of the plugin process.
WId parentWindowId() const
Gets the platform specific identifier of the window to which this plugin UI should be modal.
Accounts::Account * account() const
Gets the account being setup by this plugin.
void setReturnToAccountsList(bool value)
Sets the variable to go to accountsPage, when plugin exits.
static ProviderPluginProcess * instance()
Get the instance of the object.
void setExitData(const QVariant &data)
sets the exit data.
void setEditExistingAccount(Accounts::AccountId accountId)
Informs accounts-ui that the already existing account which the plugin instance attempted to create,...
SetupType setupType() const
ProviderPluginProcess(QObject *object=0)
Constructs the account provider plugin process.