author | alwin <alwin> | 2005-02-28 09:40:30 (UTC) |
---|---|---|
committer | alwin <alwin> | 2005-02-28 09:40:30 (UTC) |
commit | 2b64a84d39eeed5681d0ee5068c7d11a01527750 (patch) (unidiff) | |
tree | c8693340dbc5ef5e2f9afa90b690829ddff2c4bd /noncore/applets/keyhelper/keyhelperapplet/anylnk/AnyLnk.cpp | |
parent | 61fa699140c5efbb6ba0bf2a62f7e8fbf62976be (diff) | |
download | opie-2b64a84d39eeed5681d0ee5068c7d11a01527750.zip opie-2b64a84d39eeed5681d0ee5068c7d11a01527750.tar.gz opie-2b64a84d39eeed5681d0ee5068c7d11a01527750.tar.bz2 |
other keymapping tool - not working this moment, I have to check it out
- the reason is that the config file is somewhat easier to understand than
from zkbapplet and has a nice config tool.
Please don't put it into any repositories this moment.
Diffstat (limited to 'noncore/applets/keyhelper/keyhelperapplet/anylnk/AnyLnk.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/applets/keyhelper/keyhelperapplet/anylnk/AnyLnk.cpp | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/noncore/applets/keyhelper/keyhelperapplet/anylnk/AnyLnk.cpp b/noncore/applets/keyhelper/keyhelperapplet/anylnk/AnyLnk.cpp new file mode 100644 index 0000000..3c2298e --- a/dev/null +++ b/noncore/applets/keyhelper/keyhelperapplet/anylnk/AnyLnk.cpp | |||
@@ -0,0 +1,94 @@ | |||
1 | #include "AnyLnk.h" | ||
2 | #include "KHUtil.h" | ||
3 | |||
4 | void AnyLnk::loadPixmap() | ||
5 | { | ||
6 | if(m_params.count() >= 3){ | ||
7 | QString& str = m_params[2]; | ||
8 | QImage image = Resource::loadImage(str); | ||
9 | if(image.isNull() == false){ | ||
10 | const QSize& size = AppLnkManager::getIconSize(); | ||
11 | m_pixmap.convertFromImage( | ||
12 | image.smoothScale(size.width(), size.height()) ); | ||
13 | } | ||
14 | } | ||
15 | } | ||
16 | |||
17 | void AnyLnk::parseText() | ||
18 | { | ||
19 | if(m_params.count() >= 2){ | ||
20 | QString& str = m_params[1]; | ||
21 | if(str != QString::null && str.length() > 0){ | ||
22 | replaceKeyword(str); | ||
23 | replaceDate(str); | ||
24 | } | ||
25 | } | ||
26 | } | ||
27 | |||
28 | void AnyLnk::replaceText(QString& str, const QString& s1, const QString& s2) | ||
29 | { | ||
30 | int index = 0; | ||
31 | int idx; | ||
32 | int len = s1.length(); | ||
33 | idx = str.find(s1, index); | ||
34 | for(;;){ | ||
35 | idx = str.find(s1, index); | ||
36 | if(idx < 0) break; | ||
37 | str.replace(idx, len, s2); | ||
38 | index = idx; | ||
39 | } | ||
40 | } | ||
41 | |||
42 | void AnyLnk::replaceDate(QString& str) | ||
43 | { | ||
44 | time_t t; | ||
45 | struct tm lct; | ||
46 | char buf[4096]; | ||
47 | int nLen; | ||
48 | QString group; | ||
49 | |||
50 | t = ::time(NULL); | ||
51 | ::localtime_r(&t, &lct); | ||
52 | |||
53 | ConfigEx& cfg = ConfigEx::getInstance("keyhelper"); | ||
54 | group = cfg.getGroup(); | ||
55 | cfg.setGroup("Global"); | ||
56 | QString charset = cfg.readEntry("SystemCharSet", "eucJP"); | ||
57 | if(charset.length() == 0){ | ||
58 | charset = "eucJP"; | ||
59 | } | ||
60 | cfg.setGroup(group); | ||
61 | |||
62 | QTextCodec* codec = QTextCodec::codecForName(charset); | ||
63 | if(codec == NULL){ | ||
64 | codec = QTextCodec::codecForLocale(); | ||
65 | } | ||
66 | QTextDecoder* decoder = codec->makeDecoder(); | ||
67 | QTextEncoder* encoder = codec->makeEncoder(); | ||
68 | nLen = str.length(); | ||
69 | QCString localeString = encoder->fromUnicode(str, nLen); | ||
70 | |||
71 | memset(buf, '\0', sizeof(buf)); | ||
72 | int n = ::strftime(buf, sizeof(buf), localeString, &lct); | ||
73 | if(n > 0){ | ||
74 | str = decoder->toUnicode(buf, n); | ||
75 | } | ||
76 | delete decoder; | ||
77 | delete encoder; | ||
78 | } | ||
79 | |||
80 | void AnyLnk::replaceKeyword(QString& str) | ||
81 | { | ||
82 | QString txt; | ||
83 | /* clipboard text */ | ||
84 | QClipboard* cb = QApplication::clipboard(); | ||
85 | if(cb == NULL){ | ||
86 | txt == ""; | ||
87 | } else { | ||
88 | txt = cb->text(); | ||
89 | } | ||
90 | replaceText(str, "%clipboard%", txt); | ||
91 | /* current app */ | ||
92 | txt = KHUtil::currentApp(); | ||
93 | replaceText(str, "%currentapp%", txt); | ||
94 | } | ||