From 92fb302dd801e7f568cd9d66025431e79dad9771 Mon Sep 17 00:00:00 2001 From: sandman Date: Sun, 22 Dec 2002 23:46:02 +0000 Subject: New button settings -- replaces AppsKey, which does not work anymore with the new device button framework --- (limited to 'core/settings/button/buttonutils.cpp') 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 @@ +#include + +#include +#include +#include +#include +#include + +#include "buttonutils.h" + +using namespace Opie; + +struct predef_qcop { + const char *m_text; + const char *m_pixmap; + const char *m_channel; + const char *m_function; +}; + +static const predef_qcop predef [] = { + + { QT_TRANSLATE_NOOP( "ButtonSettings", "Beam VCard" ), "beam", "QPE/Application/addressbook", "beamBusinessCard()" }, + { QT_TRANSLATE_NOOP( "ButtonSettings", "Send eMail" ), "buttonsettings/mail", "QPE/Application/mail", "newMail()" }, + + + { QT_TRANSLATE_NOOP( "ButtonSettings", "Toggle Menu" ), "buttonsettings/menu", "QPE/TaskBar", "toggleMenu()" }, + { QT_TRANSLATE_NOOP( "ButtonSettings", "Toggle O-Menu" ), "buttonsettings/omenu", "QPE/TaskBar", "toggleStartMenu()" }, + { QT_TRANSLATE_NOOP( "ButtonSettings", "Show Desktop" ), "home", "QPE/Launcher", "home()" }, + { QT_TRANSLATE_NOOP( "ButtonSettings", "Toggle Recording" ), "buttonsettings/record", "QPE/VMemo", "toggleRecord()" }, + + { 0, 0, 0, 0 } +}; + + + + +ButtonUtils *ButtonUtils::ButtonUtils::inst ( ) +{ + static ButtonUtils *p = 0; + + if ( !p ) { + p = new ButtonUtils ( ); + ::atexit ( cleanup ); + } + return p; +} + +void ButtonUtils::cleanup ( ) +{ + delete inst ( ); +} + +ButtonUtils::ButtonUtils ( ) +{ + m_apps = new AppLnkSet( MimeType::appsFolderName ( )); +} + +ButtonUtils::~ButtonUtils ( ) +{ + delete m_apps; +} + +qCopInfo ButtonUtils::messageToInfo ( const OQCopMessage &c ) +{ + QCString ch = c. channel ( ); + QCString f = c. message ( ); + + if ( ch. isNull ( )) + return qCopInfo ( qApp-> translate ( "ButtonSettings", "Ignored" )); + + for ( const predef_qcop *p = predef; p-> m_text; p++ ) { + if (( ch == p-> m_channel ) && ( f == p-> m_function )) + return qCopInfo ( qApp-> translate ( "ButtonSettings", p-> m_text ), Resource::loadPixmap ( p-> m_pixmap )); + } + + if ( ch. left ( 16 ) == "QPE/Application/" ) { + QString app = ch. mid ( 16 ); + const AppLnk *applnk = m_apps-> findExec ( app ); + if ( applnk ) + app = applnk-> name ( ); + + if (( f == "raise()" ) || ( f == "nextView()" )) + return qCopInfo ( qApp-> translate ( "ButtonSettings", "Show %1" ). arg ( app ), applnk ? applnk-> pixmap ( ) : QPixmap ( )); + else + return qCopInfo ( qApp-> translate ( "ButtonSettings", "Call %1: %2" ). arg ( app ). arg ( f ), applnk ? applnk-> pixmap ( ) : QPixmap ( )); + } + else { + return qCopInfo ( qApp-> translate ( "ButtonSettings", "Call %1 %2" ). arg (( ch. left ( 4 ) == "QPE/" ) ? ch. mid ( 4 ) : ch ). arg ( f )); + } +} + + +void ButtonUtils::insertActions ( QListViewItem *here ) +{ + for ( const predef_qcop *p = predef; p-> m_text; p++ ) { + QListViewItem *item = new QListViewItem ( here, qApp-> translate ( "ButtonSettings", p-> m_text ), p-> m_channel, p-> m_function ); + item-> setPixmap ( 0, Resource::loadPixmap ( p-> m_pixmap )); + } +} + + +void ButtonUtils::insertAppLnks ( QListViewItem *here ) +{ + QStringList types = m_apps-> types ( ); + + for ( QStringList::Iterator it = types. begin ( ); it != types. end ( ); ++it ) { + QListViewItem *item = new QListViewItem ( here, m_apps-> typeName ( *it )); + item-> setPixmap ( 0, m_apps-> typePixmap ( *it )); + + for ( QListIterator appit ( m_apps-> children ( )); *appit; ++appit ) { + AppLnk *l = *appit; + + if ( l-> type ( ) == *it ) { + QListViewItem *sub = new QListViewItem ( item, l-> name ( ), QString ( "QPE/Application/" ) + l-> exec ( ), "raise()" ); + sub-> setPixmap ( 0, l-> pixmap ( )); + } + } + } +} -- cgit v0.9.0.2