00001 #include <stdlib.h>
00002
00003 #include <opie2/oresource.h>
00004
00005 #include <qapplication.h>
00006 #include <qlistview.h>
00007 #include <qpe/applnk.h>
00008 #include <qpe/mimetype.h>
00009
00010 #include "buttonutils.h"
00011
00012 using namespace Opie;
00013
00014 using namespace Opie::Core;
00015 struct predef_qcop {
00016 const char *m_text;
00017 const char *m_pixmap;
00018 const char *m_channel;
00019 const char *m_function;
00020 };
00021
00022 static const predef_qcop predef [] = {
00023
00024 { QT_TRANSLATE_NOOP( "ButtonSettings", "Beam VCard" ), "beam", "QPE/Application/addressbook", "beamBusinessCard()" },
00025 { QT_TRANSLATE_NOOP( "ButtonSettings", "Send eMail" ), "buttonsettings/mail", "QPE/Application/mail", "newMail()" },
00026
00027
00028 { QT_TRANSLATE_NOOP( "ButtonSettings", "Toggle Menu" ), "buttonsettings/menu", "QPE/TaskBar", "toggleMenu()" },
00029 { QT_TRANSLATE_NOOP( "ButtonSettings", "Toggle O-Menu" ), "buttonsettings/omenu", "QPE/TaskBar", "toggleStartMenu()" },
00030 { QT_TRANSLATE_NOOP( "ButtonSettings", "Show Desktop" ), "home", "QPE/Launcher", "home()" },
00031 { QT_TRANSLATE_NOOP( "ButtonSettings", "Toggle Recording" ), "buttonsettings/record", "QPE/VMemo", "toggleRecord()" },
00032
00033 { 0, 0, 0, 0 }
00034 };
00035
00036
00037
00038
00039 ButtonUtils *ButtonUtils::ButtonUtils::inst ( )
00040 {
00041 static ButtonUtils *p = 0;
00042
00043 if ( !p ) {
00044 p = new ButtonUtils ( );
00045 ::atexit ( cleanup );
00046 }
00047 return p;
00048 }
00049
00050 void ButtonUtils::cleanup ( )
00051 {
00052 delete inst ( );
00053 }
00054
00055 ButtonUtils::ButtonUtils ( )
00056 {
00057 m_apps = new AppLnkSet( MimeType::appsFolderName ( ));
00058 }
00059
00060 ButtonUtils::~ButtonUtils ( )
00061 {
00062 delete m_apps;
00063 }
00064
00065 qCopInfo ButtonUtils::messageToInfo ( const OQCopMessage &c )
00066 {
00067 QCString ch = c. channel ( );
00068 QCString f = c. message ( );
00069
00070
00071 if ( ch == "ignore" )
00072 return qCopInfo ( qApp-> translate ( "ButtonSettings", "<nobr>Ignored</nobr>" ));
00073
00074 for ( const predef_qcop *p = predef; p-> m_text; p++ ) {
00075 if (( ch == p-> m_channel ) && ( f == p-> m_function ))
00076 return qCopInfo ( qApp-> translate ( "ButtonSettings", p-> m_text ),
00077 Opie::Core::OResource::loadPixmap( p->m_pixmap, Opie::Core::OResource::SmallIcon ) );
00078 }
00079
00080 if ( ch. left ( 16 ) == "QPE/Application/" ) {
00081 QString app = ch. mid ( 16 );
00082 const AppLnk *applnk = m_apps-> findExec ( app );
00083 if ( applnk )
00084 app = applnk-> name ( );
00085
00086 if (( f == "raise()" ) || ( f == "nextView()" ))
00087 return qCopInfo ( qApp-> translate ( "ButtonSettings", "<nobr>Show <b>%1</b></nobr>" ). arg ( app ), applnk ? applnk-> pixmap ( ) : QPixmap ( ));
00088 else
00089 return qCopInfo ( qApp-> translate ( "ButtonSettings", "<nobr>Call <b>%1</b>: <i>%2</i></nobr>" ). arg ( app ). arg ( f ), applnk ? applnk-> pixmap ( ) : QPixmap ( ));
00090 }
00091 else {
00092 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 ));
00093 }
00094 }
00095
00096
00097 void ButtonUtils::insertActions ( QListViewItem *here )
00098 {
00099 for ( const predef_qcop *p = predef; p-> m_text; p++ ) {
00100 QListViewItem *item = new QListViewItem ( here, qApp-> translate ( "ButtonSettings", p-> m_text ), p-> m_channel, p-> m_function );
00101 item-> setPixmap ( 0, Opie::Core::OResource::loadPixmap( p->m_pixmap, Opie::Core::OResource::SmallIcon ) );
00102 }
00103 }
00104
00105
00106 void ButtonUtils::insertAppLnks ( QListViewItem *here )
00107 {
00108 QStringList types = m_apps-> types ( );
00109 QListViewItem *typeitem [types. count ( )];
00110
00111 int i = 0;
00112 for ( QStringList::Iterator it = types. begin ( ); it != types. end ( ); ++it ) {
00113 QListViewItem *item = new QListViewItem ( here, m_apps-> typeName ( *it ));
00114 item-> setPixmap ( 0, m_apps-> typePixmap ( *it ));
00115
00116 typeitem [i++] = item;
00117 }
00118
00119 for ( QListIterator <AppLnk> appit ( m_apps-> children ( )); *appit; ++appit ) {
00120 AppLnk *l = *appit;
00121
00122 int i = 0;
00123 for ( QStringList::Iterator it = types. begin ( ); it != types. end ( ); ++it ) {
00124 if ( l-> type ( ) == *it ) {
00125 QListViewItem *sub = new QListViewItem ( typeitem [i], l-> name ( ), QString ( "QPE/Application/" ) + l-> exec ( ), "raise()" );
00126 sub-> setPixmap ( 0, l-> pixmap ( ));
00127 }
00128 i++;
00129 }
00130 }
00131 }