Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

AnyLnk.cpp

Go to the documentation of this file.
00001 #include "AnyLnk.h"
00002 #include "KHUtil.h"
00003 
00004 void AnyLnk::loadPixmap()
00005 {
00006         if(m_params.count() >= 3){
00007                 m_pixmap = Opie::Core::OResource::loadPixmap( m_params[2], Opie::Core::OResource::SmallIcon );
00008         }
00009 }
00010 
00011 void AnyLnk::parseText()
00012 {
00013         if(m_params.count() >= 2){
00014                 QString& str = m_params[1];
00015                 if(str != QString::null && str.length() > 0){
00016                         replaceKeyword(str);
00017                         replaceDate(str);
00018                 }
00019         }
00020 }
00021 
00022 void AnyLnk::replaceText(QString& str, const QString& s1, const QString& s2)
00023 {
00024         int index = 0;
00025         int idx;
00026         int len = s1.length();
00027         idx = str.find(s1, index);
00028         for(;;){
00029                 idx = str.find(s1, index);
00030                 if(idx < 0) break;
00031                 str.replace(idx, len, s2);
00032                 index = idx;
00033         }
00034 }
00035 
00036 void AnyLnk::replaceDate(QString& str)
00037 {
00038         time_t t;
00039         struct tm lct;
00040         char buf[4096];
00041         int nLen;
00042         QString group;
00043 
00044         t = ::time(NULL);
00045         ::localtime_r(&t, &lct);
00046 
00047         ConfigEx& cfg = ConfigEx::getInstance("keyhelper");
00048         group = cfg.getGroup();
00049         cfg.setGroup("Global");
00050         QString charset = cfg.readEntry("SystemCharSet", "eucJP");
00051         if(charset.length() == 0){
00052                 charset = "eucJP";
00053         }
00054         cfg.setGroup(group);
00055 
00056         QTextCodec* codec = QTextCodec::codecForName(charset);
00057         if(codec == NULL){
00058                 codec = QTextCodec::codecForLocale();
00059         }
00060         QTextDecoder* decoder = codec->makeDecoder();
00061         QTextEncoder* encoder = codec->makeEncoder();
00062         nLen = str.length();
00063         QCString localeString = encoder->fromUnicode(str, nLen);
00064 
00065         memset(buf, '\0', sizeof(buf));
00066         int n = ::strftime(buf, sizeof(buf), localeString, &lct);
00067         if(n > 0){
00068                 str = decoder->toUnicode(buf, n);
00069         }
00070         delete decoder;
00071         delete encoder;
00072 }
00073 
00074 void AnyLnk::replaceKeyword(QString& str)
00075 {
00076         QString txt;
00077         /* clipboard text */
00078         QClipboard* cb = QApplication::clipboard();
00079         if(cb == NULL){
00080                 txt == "";
00081         } else {
00082                 txt = cb->text();
00083         }
00084         replaceText(str, "%clipboard%", txt);
00085         /* current app */
00086         txt = KHUtil::currentApp();
00087         replaceText(str, "%currentapp%", txt);
00088 }

Generated on Sat Nov 5 16:16:42 2005 for OPIE by  doxygen 1.4.2