summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libkdepim/externalapphandler.cpp128
-rw-r--r--libkdepim/externalapphandler.h19
2 files changed, 144 insertions, 3 deletions
diff --git a/libkdepim/externalapphandler.cpp b/libkdepim/externalapphandler.cpp
index 0128cf7..5a56d68 100644
--- a/libkdepim/externalapphandler.cpp
+++ b/libkdepim/externalapphandler.cpp
@@ -53,47 +53,53 @@ $Id$
ExternalAppHandler *ExternalAppHandler::sInstance = 0;
static KStaticDeleter<ExternalAppHandler> staticDeleter;
ExternalAppHandler::ExternalAppHandler()
{
mDefaultItems.setAutoDelete(true);
}
ExternalAppHandler::~ExternalAppHandler()
{
}
void ExternalAppHandler::loadConfig()
{
+
mDefaultItems.clear();
+ mEmailAppAvailable = UNDEFINED;
+ mPhoneAppAvailable = UNDEFINED;
+ mFaxAppAvailable = UNDEFINED;
+ mSMSAppAvailable = UNDEFINED;
+ mPagerAppAvailable = UNDEFINED;
QString opiepath = QString::fromLatin1( getenv("OPIEDIR") );
QString qtopiapath = QString::fromLatin1( getenv("QPEDIR") );
if (opiepath.isEmpty())
opiepath = qtopiapath;
//mailclients
QString mailmsg1 = "writeMail(QString,QString)";
QString mailmsg2 = "writeMail(QMap(QString,QString))";
- QString undefined = "undefined";
+ QString undefined = "";
addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::NONE_EMC, "No email client installed", undefined, undefined, undefined, undefined, undefined);
addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::OTHER_EMC, "Userdefined email client", undefined, undefined, undefined, undefined, undefined);
if (( QFile::exists( qtopiapath + "/bin/ompi" )) ||
( QFile::exists( opiepath + "/bin/ompi" )))
addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::OMPI_EMC, "OM/Pi email client", "QPE/Application/ompi", "newMail(QString)", "%1", mailmsg2, "ATTACHMENT=%1");
if ( QFile::exists( qtopiapath + "/bin/qtmail" ))
addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::QTOPIA_EMC, "Qtopia email client", "QPE/Application/qtmail", mailmsg1, ";%1", mailmsg2, "ATTACHMENT=%1");
if ( QFile::exists( opiepath + "/bin/opiemail" ))
addDefaultAppItem(ExternalAppHandler::EMAIL, KPimGlobalPrefs::OPIE_EMC, "Opie email client", "QPE/Application/opiemail", mailmsg1, ";%1", mailmsg2, "ATTACHMENT=%1");
@@ -152,32 +158,125 @@ QList<DefaultAppItem> ExternalAppHandler::getAvailableDefaultItems(Types type)
return list;
}
DefaultAppItem* ExternalAppHandler::getDefaultItem(Types type, int clientid)
{
DefaultAppItem* dai;
for ( dai=mDefaultItems.first(); dai != 0; dai=mDefaultItems.next() )
{
if (dai->_type == type && dai->_id == clientid)
return dai;
}
return 0;
}
+bool ExternalAppHandler::isEmailAppAvailable()
+{
+#ifndef DESKTOP_VERSION
+ if (mEmailAppAvailable == UNDEFINED)
+ {
+ int client = KPimGlobalPrefs::instance()->mEmailClient;
+ if (client == KPimGlobalPrefs::NONE_EMC)
+ mEmailAppAvailable = UNAVAILABLE;
+ else
+ mEmailAppAvailable = AVAILABLE;
+ }
+ return (mEmailAppAvailable == AVAILABLE);
+
+#else //DESKTOP_VERSION
+ return false;
+#endif //DESKTOP_VERSION
+}
+
+bool ExternalAppHandler::isSMSAppAvailable()
+{
+#ifndef DESKTOP_VERSION
+ if (mSMSAppAvailable == UNDEFINED)
+ {
+ int client = KPimGlobalPrefs::instance()->mSMSClient;
+ if (client == KPimGlobalPrefs::NONE_SMC)
+ mSMSAppAvailable = UNAVAILABLE;
+ else
+ mSMSAppAvailable = AVAILABLE;
+ }
+
+ return (mSMSAppAvailable == AVAILABLE);
+#else //DESKTOP_VERSION
+ return false;
+#endif //DESKTOP_VERSION
+}
+
+bool ExternalAppHandler::isPhoneAppAvailable()
+{
+#ifndef DESKTOP_VERSION
+ if (mPhoneAppAvailable == UNDEFINED)
+ {
+ int client = KPimGlobalPrefs::instance()->mPhoneClient;
+ if (client == KPimGlobalPrefs::NONE_PHC)
+ mPhoneAppAvailable = UNAVAILABLE;
+ else
+ mPhoneAppAvailable = AVAILABLE;
+ }
+
+ return (mPhoneAppAvailable == AVAILABLE);
+#else //DESKTOP_VERSION
+ return false;
+#endif //DESKTOP_VERSION
+}
+
+bool ExternalAppHandler::isFaxAppAvailable()
+{
+#ifndef DESKTOP_VERSION
+ if (mFaxAppAvailable == UNDEFINED)
+ {
+ int client = KPimGlobalPrefs::instance()->mFaxClient;
+ if (client == KPimGlobalPrefs::NONE_FAC)
+ mFaxAppAvailable = UNAVAILABLE;
+ else
+ mFaxAppAvailable = AVAILABLE;
+ }
+
+ return (mFaxAppAvailable == AVAILABLE);
+#else //DESKTOP_VERSION
+ return false;
+#endif //DESKTOP_VERSION
+}
+
+bool ExternalAppHandler::isPagerAppAvailable()
+{
+#ifndef DESKTOP_VERSION
+ if (mPagerAppAvailable == UNDEFINED)
+ {
+ int client = KPimGlobalPrefs::instance()->mPagerClient;
+ if (client == KPimGlobalPrefs::NONE_PAC)
+ mPagerAppAvailable = UNAVAILABLE;
+ else
+ mPagerAppAvailable = AVAILABLE;
+ }
+
+ return (mPagerAppAvailable == AVAILABLE);
+#else //DESKTOP_VERSION
+ return false;
+#endif //DESKTOP_VERSION
+}
+
+/**************************************************************************
+ *
+ **************************************************************************/
//calls the emailapplication with a number of attachments that need to be send (Seperated by Comma)
bool ExternalAppHandler::mailAttachments( const QString& urls )
{
#ifndef DESKTOP_VERSION
QString channel;
QString message2;
QString parameters2;
int client = KPimGlobalPrefs::instance()->mEmailClient;
if (client == KPimGlobalPrefs::OTHER_EMC)
{
channel = KPimGlobalPrefs::instance()->mEmailOtherChannel;
@@ -203,32 +302,35 @@ bool ExternalAppHandler::mailAttachments( const QString& urls )
QCopEnvelope e(channel.latin1(), message2.latin1());
//US we need no names in the To field. The emailadresses are enough
passParameter(&e, parameters2, urls);
#else
KMessageBox::sorry( 0, i18n( "This version does not support the sending of emails." ) );
#endif
return true;
}
+/**************************************************************************
+ *
+ **************************************************************************/
//calls the emailapplication and creates a mail with parameter emails as recipients
bool ExternalAppHandler::mailToContacts( const QString& emails )
{
#ifndef DESKTOP_VERSION
QString channel;
QString message;
QString parameters;
int client = KPimGlobalPrefs::instance()->mEmailClient;
if (client == KPimGlobalPrefs::OTHER_EMC)
{
channel = KPimGlobalPrefs::instance()->mEmailOtherChannel;
message = KPimGlobalPrefs::instance()->mEmailOtherMessage;
@@ -256,32 +358,35 @@ bool ExternalAppHandler::mailToContacts( const QString& emails )
qDebug("passing emailadresses:(%s) as parameter in the form %s to QCopEnvelope", emails.latin1(), parameters.latin1());
QCopEnvelope e(channel.latin1(), message.latin1());
//US we need no names in the To field. The emailadresses are enough
passParameter(&e, parameters, emails);
#else
KMessageBox::sorry( 0, i18n( "This version does not support the sending of emails." ) );
#endif
return true;
}
+/**************************************************************************
+ *
+ **************************************************************************/
//calls the phoneapplication with the number
bool ExternalAppHandler::callByPhone( const QString& phonenumber )
{
#ifndef DESKTOP_VERSION
QString channel;
QString message;
QString parameters;
int client = KPimGlobalPrefs::instance()->mPhoneClient;
if (client == KPimGlobalPrefs::OTHER_PHC)
{
channel = KPimGlobalPrefs::instance()->mPhoneOtherChannel;
message = KPimGlobalPrefs::instance()->mPhoneOtherMessage;
parameters = KPimGlobalPrefs::instance()->mPhoneOtherMessageParameters;
@@ -308,32 +413,36 @@ bool ExternalAppHandler::callByPhone( const QString& phonenumber )
qDebug("passing phonenumber:(%s) as parameter in the form %s to QCopEnvelope", phonenumber.latin1(), parameters.latin1());
QCopEnvelope e(channel.latin1(), message.latin1());
//US we need no names in the To field. The emailadresses are enough
passParameter(&e, parameters, phonenumber);
#else
KMessageBox::sorry( 0, i18n( "This version does not support phonecalls." ) );
#endif
return true;
}
+/**************************************************************************
+ *
+ **************************************************************************/
+
//calls the smsapplication with the number
bool ExternalAppHandler::callBySMS( const QString& phonenumber )
{
#ifndef DESKTOP_VERSION
QString channel;
QString message;
QString parameters;
int client = KPimGlobalPrefs::instance()->mSMSClient;
if (client == KPimGlobalPrefs::OTHER_SMC)
{
channel = KPimGlobalPrefs::instance()->mSMSOtherChannel;
message = KPimGlobalPrefs::instance()->mSMSOtherMessage;
parameters = KPimGlobalPrefs::instance()->mSMSOtherMessageParameters;
}
@@ -359,32 +468,36 @@ bool ExternalAppHandler::callBySMS( const QString& phonenumber )
qDebug("passing phonenumber:(%s) as parameter in the form %s to QCopEnvelope", phonenumber.latin1(), parameters.latin1());
QCopEnvelope e(channel.latin1(), message.latin1());
//US we need no names in the To field. The emailadresses are enough
passParameter(&e, parameters, phonenumber);
#else
KMessageBox::sorry( 0, i18n( "This version does not support the sending of sms." ) );
#endif
return true;
}
+/**************************************************************************
+ *
+ **************************************************************************/
+
//calls the pagerapplication with the number
bool ExternalAppHandler::callByPager( const QString& pagernumber )
{
#ifndef DESKTOP_VERSION
QString channel;
QString message;
QString parameters;
int client = KPimGlobalPrefs::instance()->mPagerClient;
if (client == KPimGlobalPrefs::OTHER_PAC)
{
channel = KPimGlobalPrefs::instance()->mPagerOtherChannel;
message = KPimGlobalPrefs::instance()->mPagerOtherMessage;
parameters = KPimGlobalPrefs::instance()->mPagerOtherMessageParameters;
}
@@ -410,32 +523,36 @@ bool ExternalAppHandler::callByPager( const QString& pagernumber )
qDebug("passing pagernumber:(%s) as parameter in the form %s to QCopEnvelope", pagernumber.latin1(), parameters.latin1());
QCopEnvelope e(channel.latin1(), message.latin1());
//US we need no names in the To field. The emailadresses are enough
passParameter(&e, parameters, pagernumber);
#else
KMessageBox::sorry( 0, i18n( "This version does not support paging." ) );
#endif
return true;
}
+/**************************************************************************
+ *
+ **************************************************************************/
+
//calls the faxapplication with the number
bool ExternalAppHandler::callByFax( const QString& faxnumber )
{
#ifndef DESKTOP_VERSION
QString channel;
QString message;
QString parameters;
int client = KPimGlobalPrefs::instance()->mFaxClient;
if (client == KPimGlobalPrefs::OTHER_FAC)
{
channel = KPimGlobalPrefs::instance()->mFaxOtherChannel;
message = KPimGlobalPrefs::instance()->mFaxOtherMessage;
parameters = KPimGlobalPrefs::instance()->mFaxOtherMessageParameters;
}
@@ -461,42 +578,47 @@ bool ExternalAppHandler::callByFax( const QString& faxnumber )
qDebug("passing faxnumber:(%s) as parameter in the form %s to QCopEnvelope", faxnumber.latin1(), parameters.latin1());
QCopEnvelope e(channel.latin1(), message.latin1());
//US we need no names in the To field. The emailadresses are enough
passParameter(&e, parameters, faxnumber);
#else
KMessageBox::sorry( 0, i18n( "This version does not support the sending of faxes." ) );
#endif
return true;
}
-
-
+/**************************************************************************
+ *
+ **************************************************************************/
QString& ExternalAppHandler::translateMessage(QString& message, const QString& param1) const
{
return message.replace( QRegExp("%1"), param1 );
}
+/**************************************************************************
+ *
+ **************************************************************************/
+
void ExternalAppHandler::passParameter(QCopEnvelope* e, const QString& parameters, const QString& param1) const
{
#ifndef DESKTOP_VERSION
QMap<QString, QString> valmap;
bool useValMap = false;
// first extract all parts of the parameters.
QStringList paramlist = QStringList::split(";", parameters);
//Now check how many parts we have.
//=0 :no params to pass
//>0 :parameters to pass
for ( QStringList::Iterator it = paramlist.begin(); it != paramlist.end(); ++it )
{
QString param = (*it);
QStringList keyvallist = QStringList::split("=", param);
diff --git a/libkdepim/externalapphandler.h b/libkdepim/externalapphandler.h
index 3ecf1b1..efcdd89 100644
--- a/libkdepim/externalapphandler.h
+++ b/libkdepim/externalapphandler.h
@@ -62,59 +62,78 @@ class DefaultAppItem
class ExternalAppHandler
{
public:
virtual ~ExternalAppHandler();
static ExternalAppHandler *instance();
enum Types {
EMAIL = 0,
PHONE = 1,
SMS = 2,
FAX = 3,
PAGER = 4
};
+ enum Availability {
+ UNDEFINED = -1,
+ UNAVAILABLE = 0,
+ AVAILABLE = 1
+ };
+
//calls the emailapplication with a number of attachments that need to be send
bool mailAttachments( const QString& urls );
//calls the emailapplication and creates a mail with parameter emails as recipients
bool mailToContacts( const QString& emails );
//calls the phoneapplication with the number
bool callByPhone( const QString& phonenumber );
//calls the smsapplication with the number
bool callBySMS( const QString& phonenumber );
//calls the pagerapplication with the number
bool callByPager( const QString& pagernumber );
//calls the faxapplication with the number
bool callByFax( const QString& faxnumber );
+ bool isEmailAppAvailable();
+ bool isSMSAppAvailable();
+ bool isPhoneAppAvailable();
+ bool isFaxAppAvailable();
+ bool isPagerAppAvailable();
+
+
//loadConfig clears the cache and checks again if the applications are available or not
void loadConfig();
QList<DefaultAppItem> getAvailableDefaultItems(Types);
DefaultAppItem* getDefaultItem(Types, int);
private:
ExternalAppHandler();
QList<DefaultAppItem> mDefaultItems;
+ Availability mEmailAppAvailable;
+ Availability mPhoneAppAvailable;
+ Availability mFaxAppAvailable;
+ Availability mSMSAppAvailable;
+ Availability mPagerAppAvailable;
+
void addDefaultAppItem(Types type, int id, const QString& label, const QString& channel, const QString& message, const QString& parameters, const QString& message2, const QString& parameters2);
QString& translateMessage(QString& message, const QString& emails) const;
void passParameter(QCopEnvelope* e, const QString& parameters, const QString& param1) const;
static ExternalAppHandler *sInstance;
};
#endif