accounts-qt 0.31
|
00001 /* 00002 * This file is part of libaccounts-qt 00003 * 00004 * Copyright (C) 2009-2010 Nokia Corporation. 00005 * 00006 * Contact: Alberto Mardegan <alberto.mardegan@nokia.com> 00007 * 00008 * This library is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public License 00010 * version 2.1 as published by the Free Software Foundation. 00011 * 00012 * This library is distributed in the hope that it will be useful, but 00013 * WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 00020 * 02110-1301 USA 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 //qDebug ( args.at(i).toLocal8Bit().constData()); 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 //qDebug ("command: %s",cmd.toLocal8Bit().constData()); 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 // qDebug ( acc->displayName().toLocal8Bit().constData()); 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 //QVariant val; 00111 //acc->value(keylist.at(i), val); 00112 qDebug() << keylist.at(i).toLocal8Bit().constData() << " = " << acc->valueAsString(keylist.at(i)); 00113 } 00114 } 00115 acc=NULL; 00116 } 00117 } 00118 } 00119 /* 00120 Profile p=Profile(QString("test")); 00121 p.setValue(QString("name"),QString("test_value")); 00122 const QStringList plist=p.allKeys(); 00123 for (int i = 0; i < plist.size(); ++i) 00124 qDebug ( plist.at(i).toLocal8Bit().constData()); 00125 */ 00126 00127 00128 // use this when doing something async 00129 // QObject::connect(&hello, SIGNAL(clicked()), &app, SLOT(quit())); 00130 // ret = app.exec(); 00131 00132 delete accountMgr; 00133 00134 return ret; 00135 } 00136