Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <QCoreApplication>
00024 #include <QDebug>
00025 #include "account-tool.h"
00026
00027 using namespace Accounts;
00028
00029 int main(int argc, char **argv)
00030 {
00031 int ret = 0;
00032 QCoreApplication app(argc, argv);
00033
00034 QStringList args = QCoreApplication::arguments ();
00035 QString cmd;
00036 QString param;
00037 QString type;
00038
00039 if(args.size()<=1)
00040 {
00041 qDebug("account-tool");
00042 qDebug("Usage: account-tool [-t type] [options]");
00043 qDebug(" -l list accounts");
00044 qDebug(" -L list account names");
00045 qDebug(" -k [#] list keys for account #");
00046 qDebug(" -t type list accounts with type type");
00047
00048 }
00049 for (int i = 0; i < args.size(); ++i)
00050 {
00051
00052
00053 if(args.at(i).startsWith("-"))
00054 {
00055 cmd = args.at(i).mid(1);
00056 if(args.size()>i+1)
00057 {
00058 if(cmd == QString("t"))
00059 {
00060 type =args.at(i+1);
00061 }
00062 else
00063 param = args.at(i+1);
00064 }
00065
00066 }
00067 }
00068
00069 Manager* accountMgr = new Manager();
00070
00071 const AccountIdList acclist=accountMgr->accountList(type);
00072
00073 if (cmd == QString("l")) {
00074 qDebug("list accounts:");
00075 for (int i = 0; i < acclist.size(); ++i)
00076 qDebug ( "%u", acclist.at(i));
00077 }
00078
00079 if (cmd == QString("L")) {
00080 qDebug("List accounts:");
00081 for (int i = 0; i < acclist.size(); ++i)
00082 {
00083 qDebug ( "Account: %u", acclist.at(i));
00084 Account* acc = accountMgr->account(acclist.at(i));
00085 if (acc!=NULL)
00086 {
00087 qDebug ( "%s", acc->displayName().toLocal8Bit().constData());
00088 }
00089
00090 acc=NULL;
00091 }
00092 }
00093
00094 if (cmd == QString("k")) {
00095 qDebug("List keys:");
00096 for (int i = 0; i < acclist.size(); ++i)
00097 {
00098 if(param.isEmpty() || param.toInt()==int(acclist.at(i)))
00099 {
00100 qDebug ( "Account: %u", acclist.at(i));
00101 Account* acc = accountMgr->account(acclist.at(i));
00102 if (acc!=NULL)
00103 {
00104 qDebug ( "Display name: %s", acc->displayName().toLocal8Bit().constData());
00105 qDebug ( "CredentialsId: %d", acc->credentialsId());
00106 qDebug ( "Provider: %s", acc->providerName().toLocal8Bit().constData());
00107
00108 const QStringList keylist=acc->allKeys();
00109 for (int i = 0; i < keylist.size(); ++i) {
00110
00111
00112 qDebug() << keylist.at(i).toLocal8Bit().constData() << " = " << acc->valueAsString(keylist.at(i));
00113 }
00114 }
00115 acc=NULL;
00116 }
00117 }
00118 }
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 delete accountMgr;
00133
00134 return ret;
00135 }
00136