00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "addressdetails.h"
00022
00023 #include <kabc/phonenumber.h>
00024 #include <kiconloader.h>
00025 #include <klocale.h>
00026 #include <kglobalsettings.h>
00027 #include <kdebug.h>
00028 #include <QTextDocument>
00029
00030 #include <libkmobiletools/kmobiletoolshelper.h>
00031 #include <libkmobiletools/engine.h>
00032 #include <libkmobiletools/devicesconfig.h>
00033 #include <popupnumber.h>
00034 #include <popupaddressee.h>
00035
00036 using namespace KMobileTools;
00037
00038 addressDetails::addressDetails(QWidget *parentWidget, const QString &objectname,QObject *parent)
00039 : KHTMLPart(parentWidget, parent)
00040 {
00041 setObjectName(objectname);
00042 kDebug() <<"addressDetails:: device name:" << objectName();
00043 connect(this, SIGNAL(popupMenu(const QString &,const QPoint &)), SLOT(popupMenu ( const QString &, const QPoint &) ) );
00044 connect( browserExtension(), SIGNAL( openUrlRequest(const KUrl &, const KParts::OpenUrlArguments &, const KParts::BrowserArguments &) ), this, SLOT( openUrlRequest(const KUrl &) ) );
00045 showHP();
00046 }
00047
00048
00049 addressDetails::~addressDetails()
00050 {
00051 }
00052
00053
00054 #include "addressdetails.moc"
00055
00056 const QString addressDetails::getTemplate()
00057 {
00058 return KMobiletoolsHelper::getTemplate()
00059 .arg( KMobiletoolsHelper::getFooterLink( i18nc("Add new contact", "Add new"), "contact-add", "contact:add" ) )
00060 .arg( KMobiletoolsHelper::getFooterLink( i18nc("Fetch phonebook from the mobile", "Reload"), "view-refresh", "contact:refresh" ) )
00061 .arg( KMobiletoolsHelper::getFooterLink( i18nc("Import phonebook", "Import"), "document-import", "contact:import" ) )
00062 .arg( KMobiletoolsHelper::getFooterLink( i18nc("Export phonebook", "Export"), "document-export", "contact:export" ) );
00063 }
00067 void addressDetails::showAddressee(const KABC::Addressee &addressee, bool readOnly)
00068 {
00069 if(addressee.isEmpty()) return;
00070 ro=readOnly;
00071 QString htmlData;
00072
00073
00074
00075
00076
00077 QString renderData=getTemplate().arg( KIconLoader::global()->iconPath("x-office-contact", -KIconLoader::SizeHuge, false) )
00078 .arg( addressee.formattedName() );
00079 if(readOnly) renderData=renderData.arg(QString() ).arg(QString() );
00080 else renderData=renderData
00081 .arg( KMobiletoolsHelper::getFooterLink( i18nc("Edit Contact", "Edit") , "document-properties", "contact:edit" ) )
00082 .arg( KMobiletoolsHelper::getFooterLink( i18nc("Delete Contact", "Delete") , "edit-delete", "contact:del" ) );
00083
00084
00085
00086
00087
00088
00089 KABC::PhoneNumber::List numberList = addressee.phoneNumbers();
00090 for ( KABC::PhoneNumber::List::Iterator it = numberList.begin(); it != numberList.end(); it++ )
00091 {
00092 htmlData += QString("<p><b>%1:</b> <a href=\"number:").arg( (*it).typeLabel() );
00093 htmlData+=QString::fromLatin1( KUrl::toPercentEncoding( (*it).number(), "/" ) )
00094 + "\">" +Qt::escape( (*it).number() ) + "</a></p>\n";
00095 }
00096
00097 QString storedOn;
00098 switch( addressee.custom("KMobileTools","memslot").toInt() ){
00099 case KMobileTools::Engine::PB_SIM:
00100 storedOn=PB_SIM_TEXT;
00101 break;
00102 case KMobileTools::Engine::PB_Phone:
00103 storedOn=PB_PHONE_TEXT;
00104 break;
00105 case KMobileTools::Engine::PB_DataCard:
00106 storedOn=PB_DATACARD_TEXT;
00107 break;
00108 default:
00109 storedOn=i18n("not available");
00110 }
00111
00112 htmlData+=i18n("<p>Stored on: <b>%1</b></p>", storedOn);
00113
00114
00115
00116
00117
00118
00119 renderData=renderData.arg(htmlData );
00120 begin();
00121 write( renderData );
00122 end();
00123 p_addressee=addressee;
00124 }
00125
00126
00130 void addressDetails::popupMenu ( const QString &url, const QPoint &point)
00131 {
00132 KUrl kurl(url);
00133 KMenu *popup=0;
00134 if(kurl.protocol()=="number")
00135 popup=new popupNumber(objectName(), kurl.path(), 0);
00136 if( url.isNull() )
00137 {
00138 if(p_addressee.isEmpty()) return;
00139 popup=new popupAddressee(objectName(), p_addressee, 0, ro );
00140 connect(popup, SIGNAL( editClicked(KABC::Addressee) ), this, SIGNAL(editClicked(KABC::Addressee) ) );
00141 connect(popup, SIGNAL( delContact() ), this, SIGNAL(delContact() ) );
00142 }
00143 if(!popup) return;
00144 popup->exec(point);
00145 }
00146
00147
00148 void addressDetails::openUrlRequest(const KUrl &url)
00149 {
00150 if(url.path() == "refresh") emit refreshClicked();
00151 if(url.path() == "edit") emit editClicked(p_addressee);
00152 if(url.path() == "add" ) emit addContact();
00153 if(url.path() == "del" ) emit delContact();
00154 if(url.path() == "import") emit importPB();
00155 if(url.path() == "export") emit exportPB();
00156 if(url.protocol() == "number") emit dial(url.path() );
00157 }
00158
00159
00163 void addressDetails::showHP()
00164 {
00165 begin();
00166 write( getTemplate().arg(KIconLoader::global()->iconPath("view-pim-contacts", -KIconLoader::SizeHuge, false) )
00167 .arg( i18n("%1 AddressBook", DEVCFG(objectName() )->devicename() ) )
00168 .arg("") .arg("")
00169 .arg( i18n("<p><i>Click a contact on the left list to see details, or \"Reload\" to update the contacts list.</i></p>") )
00170 );
00171 end();
00172 p_addressee=KABC::Addressee();
00173 }