kmobiletools
picksmscenter.cpp
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 #include "picksmscenter.h"
00021 #include "kmobiletoolshelper.h"
00022
00023 #include <qlayout.h>
00024 #include <klocale.h>
00025 #include <kconfig.h>
00026 #include <k3listviewsearchline.h>
00027 #include <k3listview.h>
00028 #include <kglobal.h>
00029 #include <kstandarddirs.h>
00030 #include <kmessagebox.h>
00031
00032 using namespace KMobileTools;
00033
00034 namespace KMobileTools {
00035
00036 class PickSMSCenterPrivate {
00037 public:
00038 PickSMSCenterPrivate()
00039 : listview(NULL), config(NULL) {}
00040
00041 K3ListView *listview;
00042 QString s_smsCenter;
00043 KConfig *config;
00044 };
00045
00046
00047 PickSMSCenter::PickSMSCenter(QWidget *parent)
00048 : KDialog(parent), d(new PickSMSCenterPrivate)
00049 {
00050 setCaption( i18nc( "Pick SMS Center from list", "Choose Your Operator SMS Center") );
00051 setButtons( Ok | Cancel );
00052 enableButtonOk (false);
00053 QVBoxLayout *lay=new QVBoxLayout(mainWidget());
00054 K3ListViewSearchLineWidget *slwidget=new K3ListViewSearchLineWidget( 0, this);
00055 lay->addWidget(slwidget);
00056 d->listview=new K3ListView(this);
00057 lay->addWidget(d->listview);
00058 d->listview->addColumn( i18nc("Network name for SMS Center", "Network Name") );
00059 d->listview->addColumn( i18nc("SMS Center number", "Number") );
00060 connect(d->listview, SIGNAL(clicked( Q3ListViewItem* )), this, SLOT(clicked( Q3ListViewItem* ) ) );
00061 connect(d->listview, SIGNAL(doubleClicked( Q3ListViewItem*, const QPoint&, int ) ), this, SLOT(doubleClicked( Q3ListViewItem*, const QPoint&, int )) );
00062 slwidget->createSearchLine(d->listview);
00063 resize(400,500);
00064 initList();
00065 }
00066
00067
00068 PickSMSCenter::~PickSMSCenter()
00069 {
00070 delete d;
00071 }
00072
00073
00074 #include "picksmscenter.moc"
00075
00076
00080 void PickSMSCenter::initList()
00081 {
00082 QString file=KGlobal::dirs()->findResource( "data", "kmobiletools/operatorsdata" );
00083 if(file.isNull() )
00084 {
00085 KMessageBox::error( this, i18n("Operators data not found.") );
00086 return;
00087 }
00088
00089 d->config=new KConfig( file, KConfig::NoGlobals );
00090 QStringList operators=d->config->groupList();
00091 for(QStringList::Iterator it=operators.begin(); it!=operators.end(); ++it)
00092 {
00093 const KConfigGroup cg( d->config, *it );
00094 if(cg.readEntry( "smscenter").isNull() ) continue;
00095 new K3ListViewItem(d->listview, *it, cg.readEntry( "smscenter") );
00096 }
00097 delete d->config;
00098 }
00099
00100
00104 void PickSMSCenter::clicked ( Q3ListViewItem * item )
00105 {
00106 if(!item )
00107 {
00108 enableButtonOk(false);
00109 d->s_smsCenter.clear();
00110 return;
00111 }
00112 enableButtonOk( true );
00113 d->s_smsCenter=item->text(1);
00114 }
00115
00116
00120 void PickSMSCenter::doubleClicked( Q3ListViewItem *item, const QPoint &, int )
00121 {
00122 clicked(item);
00123 if(!item)return;
00124 done(Accepted);
00125 }
00126
00127 const QString PickSMSCenter::smsCenter() { return d->s_smsCenter;}
00128
00129
00133 QString PickSMSCenter::smsCenterName(const QString &smsCenter)
00134 {
00135 QString file=KGlobal::dirs()->findResource( "data", "kmobiletools/operatorsdata" );
00136
00137
00138 KConfig *config=new KConfig( file, KConfig::NoGlobals );
00139 QStringList operators=config->groupList();
00140 for(QStringList::Iterator it=operators.begin(); it!=operators.end(); ++it)
00141 {
00142 const KConfigGroup cg( config, *it );
00143 if( KMobileTools::KMobiletoolsHelper::compareNumbers( cg.readEntry( "smscenter"), smsCenter ) )
00144 {
00145 delete config;
00146 return *it;
00147 }
00148 }
00149 delete config;
00150 return smsCenter;
00151 }
00152
00153 }