summaryrefslogtreecommitdiff
path: root/core/settings/button/buttonutils.cpp
Unidiff
Diffstat (limited to 'core/settings/button/buttonutils.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--core/settings/button/buttonutils.cpp119
1 files changed, 119 insertions, 0 deletions
diff --git a/core/settings/button/buttonutils.cpp b/core/settings/button/buttonutils.cpp
new file mode 100644
index 0000000..bb70047
--- a/dev/null
+++ b/core/settings/button/buttonutils.cpp
@@ -0,0 +1,119 @@
1#include <stdlib.h>
2
3#include <qapplication.h>
4#include <qlistview.h>
5#include <qpe/applnk.h>
6#include <qpe/mimetype.h>
7#include <qpe/resource.h>
8
9#include "buttonutils.h"
10
11using namespace Opie;
12
13struct predef_qcop {
14 const char *m_text;
15 const char *m_pixmap;
16 const char *m_channel;
17 const char *m_function;
18};
19
20static const predef_qcop predef [] = {
21
22 { QT_TRANSLATE_NOOP( "ButtonSettings", "Beam VCard" ), "beam", "QPE/Application/addressbook", "beamBusinessCard()" },
23 { QT_TRANSLATE_NOOP( "ButtonSettings", "Send eMail" ), "buttonsettings/mail", "QPE/Application/mail", "newMail()" },
24
25
26 { QT_TRANSLATE_NOOP( "ButtonSettings", "Toggle Menu" ), "buttonsettings/menu", "QPE/TaskBar", "toggleMenu()" },
27 { QT_TRANSLATE_NOOP( "ButtonSettings", "Toggle O-Menu" ), "buttonsettings/omenu", "QPE/TaskBar", "toggleStartMenu()" },
28 { QT_TRANSLATE_NOOP( "ButtonSettings", "Show Desktop" ), "home", "QPE/Launcher", "home()" },
29 { QT_TRANSLATE_NOOP( "ButtonSettings", "Toggle Recording" ), "buttonsettings/record", "QPE/VMemo", "toggleRecord()" },
30
31 { 0, 0, 0, 0 }
32};
33
34
35
36
37ButtonUtils *ButtonUtils::ButtonUtils::inst ( )
38{
39 static ButtonUtils *p = 0;
40
41 if ( !p ) {
42 p = new ButtonUtils ( );
43 ::atexit ( cleanup );
44 }
45 return p;
46}
47
48void ButtonUtils::cleanup ( )
49{
50 delete inst ( );
51}
52
53ButtonUtils::ButtonUtils ( )
54{
55 m_apps = new AppLnkSet( MimeType::appsFolderName ( ));
56}
57
58ButtonUtils::~ButtonUtils ( )
59{
60 delete m_apps;
61}
62
63qCopInfo ButtonUtils::messageToInfo ( const OQCopMessage &c )
64{
65 QCString ch = c. channel ( );
66 QCString f = c. message ( );
67
68 if ( ch. isNull ( ))
69 return qCopInfo ( qApp-> translate ( "ButtonSettings", "<nobr>Ignored</nobr>" ));
70
71 for ( const predef_qcop *p = predef; p-> m_text; p++ ) {
72 if (( ch == p-> m_channel ) && ( f == p-> m_function ))
73 return qCopInfo ( qApp-> translate ( "ButtonSettings", p-> m_text ), Resource::loadPixmap ( p-> m_pixmap ));
74 }
75
76 if ( ch. left ( 16 ) == "QPE/Application/" ) {
77 QString app = ch. mid ( 16 );
78 const AppLnk *applnk = m_apps-> findExec ( app );
79 if ( applnk )
80 app = applnk-> name ( );
81
82 if (( f == "raise()" ) || ( f == "nextView()" ))
83 return qCopInfo ( qApp-> translate ( "ButtonSettings", "<nobr>Show <b>%1</b></nobr>" ). arg ( app ), applnk ? applnk-> pixmap ( ) : QPixmap ( ));
84 else
85 return qCopInfo ( qApp-> translate ( "ButtonSettings", "<nobr>Call <b>%1</b>: <i>%2</i></nobr>" ). arg ( app ). arg ( f ), applnk ? applnk-> pixmap ( ) : QPixmap ( ));
86 }
87 else {
88 return qCopInfo ( qApp-> translate ( "ButtonSettings", "<nobr>Call <b>%1</b> <i>%2</i></nobr>" ). arg (( ch. left ( 4 ) == "QPE/" ) ? ch. mid ( 4 ) : ch ). arg ( f ));
89 }
90}
91
92
93void ButtonUtils::insertActions ( QListViewItem *here )
94{
95 for ( const predef_qcop *p = predef; p-> m_text; p++ ) {
96 QListViewItem *item = new QListViewItem ( here, qApp-> translate ( "ButtonSettings", p-> m_text ), p-> m_channel, p-> m_function );
97 item-> setPixmap ( 0, Resource::loadPixmap ( p-> m_pixmap ));
98 }
99}
100
101
102void ButtonUtils::insertAppLnks ( QListViewItem *here )
103{
104 QStringList types = m_apps-> types ( );
105
106 for ( QStringList::Iterator it = types. begin ( ); it != types. end ( ); ++it ) {
107 QListViewItem *item = new QListViewItem ( here, m_apps-> typeName ( *it ));
108 item-> setPixmap ( 0, m_apps-> typePixmap ( *it ));
109
110 for ( QListIterator <AppLnk> appit ( m_apps-> children ( )); *appit; ++appit ) {
111 AppLnk *l = *appit;
112
113 if ( l-> type ( ) == *it ) {
114 QListViewItem *sub = new QListViewItem ( item, l-> name ( ), QString ( "QPE/Application/" ) + l-> exec ( ), "raise()" );
115 sub-> setPixmap ( 0, l-> pixmap ( ));
116 }
117 }
118 }
119}