accounts-qt  1.2
account-tool.cpp
1 /*
2  * This file is part of libaccounts-qt
3  *
4  * Copyright (C) 2009-2011 Nokia Corporation.
5  *
6  * Contact: Alberto Mardegan <alberto.mardegan@nokia.com>
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 License
10  * version 2.1 as published by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  */
22 
23 #include <QCoreApplication>
24 #include <QDebug>
25 #include "account-tool.h"
26 
27 using namespace Accounts;
28 
29 int main(int argc, char **argv)
30 {
31  int ret = 0;
32  QCoreApplication app(argc, argv);
33 
34  QStringList args = QCoreApplication::arguments ();
35  QString cmd;
36  QString param;
37  QString type;
38 
39  if(args.size()<=1)
40  {
41  qDebug("account-tool");
42  qDebug("Usage: account-tool [-t type] [options]");
43  qDebug(" -l list accounts");
44  qDebug(" -L list account names");
45  qDebug(" -k [#] list keys for account #");
46  qDebug(" -t type list accounts with type type");
47 
48  }
49  for (int i = 0; i < args.size(); ++i)
50  {
51  //qDebug ( args.at(i).toLocal8Bit().constData());
52 
53  if(args.at(i).startsWith("-"))
54  {
55  cmd = args.at(i).mid(1);
56  if(args.size()>i+1)
57  {
58  if(cmd == QString("t"))
59  {
60  type =args.at(i+1);
61  }
62  else
63  param = args.at(i+1);
64  }
65  //qDebug ("command: %s",cmd.toLocal8Bit().constData());
66  }
67  }
68 
69  Manager* accountMgr = new Manager();
70 
71  const AccountIdList acclist=accountMgr->accountList(type);
72 
73  if (cmd == QString("l")) {
74  qDebug("list accounts:");
75  for (int i = 0; i < acclist.size(); ++i)
76  qDebug ( "%u", acclist.at(i));
77  }
78 
79  if (cmd == QString("L")) {
80  qDebug("List accounts:");
81  for (int i = 0; i < acclist.size(); ++i)
82  {
83  qDebug ( "Account: %u", acclist.at(i));
84  Account* acc = accountMgr->account(acclist.at(i));
85  if (acc!=NULL)
86  {
87  qDebug ( "%s", acc->displayName().toLocal8Bit().constData());
88  }
89  // qDebug ( acc->displayName().toLocal8Bit().constData());
90  acc=NULL;
91  }
92  }
93 
94  if (cmd == QString("k")) {
95  qDebug("List keys:");
96  for (int i = 0; i < acclist.size(); ++i)
97  {
98  if(param.isEmpty() || param.toInt()==int(acclist.at(i)))
99  {
100  qDebug ( "Account: %u", acclist.at(i));
101  Account* acc = accountMgr->account(acclist.at(i));
102  if (acc!=NULL)
103  {
104  qDebug ( "Display name: %s", acc->displayName().toLocal8Bit().constData());
105  qDebug ( "CredentialsId: %d", acc->credentialsId());
106  qDebug ( "Provider: %s", acc->providerName().toLocal8Bit().constData());
107 
108  const QStringList keylist=acc->allKeys();
109  for (int i = 0; i < keylist.size(); ++i) {
110  //QVariant val;
111  //acc->value(keylist.at(i), val);
112  qDebug() << keylist.at(i).toLocal8Bit().constData() << " = " << acc->valueAsString(keylist.at(i));
113  }
114  }
115  acc=NULL;
116  }
117  }
118  }
119 /*
120  Profile p=Profile(QString("test"));
121  p.setValue(QString("name"),QString("test_value"));
122  const QStringList plist=p.allKeys();
123  for (int i = 0; i < plist.size(); ++i)
124  qDebug ( plist.at(i).toLocal8Bit().constData());
125 */
126 
127 
128 // use this when doing something async
129 // QObject::connect(&hello, SIGNAL(clicked()), &app, SLOT(quit()));
130 // ret = app.exec();
131 
132  delete accountMgr;
133 
134  return ret;
135 }
136