-rw-r--r-- | core/settings/button/remapdlg.cpp | 72 | ||||
-rw-r--r-- | core/settings/citytime/citytime.cpp | 94 | ||||
-rw-r--r-- | core/settings/citytime/citytimebase.cpp | 120 | ||||
-rw-r--r-- | core/settings/citytime/zonemap.cpp | 402 | ||||
-rw-r--r-- | core/settings/launcher/doctabsettings.cpp | 6 | ||||
-rw-r--r-- | core/settings/launcher/inputmethodsettings.cpp | 6 | ||||
-rw-r--r-- | core/settings/launcher/tabdialog.cpp | 632 | ||||
-rw-r--r-- | core/settings/launcher/taskbarsettings.cpp | 196 | ||||
-rw-r--r-- | core/settings/light-and-power/light.cpp | 387 | ||||
-rw-r--r-- | core/settings/security/security.cpp | 58 | ||||
-rw-r--r-- | core/settings/security/security.pro | 14 | ||||
-rw-r--r-- | core/symlinker/main.cpp | 220 | ||||
-rw-r--r-- | core/symlinker/symlinker.pro | 18 | ||||
-rw-r--r-- | core/tools/quicklauncher/main.cpp | 231 |
14 files changed, 1255 insertions, 1201 deletions
diff --git a/core/settings/button/remapdlg.cpp b/core/settings/button/remapdlg.cpp index 4effebc..cadb955 100644 --- a/core/settings/button/remapdlg.cpp +++ b/core/settings/button/remapdlg.cpp @@ -1,155 +1,161 @@ + +#include "remapdlg.h" +#include "buttonutils.h" + +/* OPIE */ +#include <opie2/odebug.h> + +/* QT */ #include <qlistview.h> #include <qcombobox.h> #include <qtimer.h> -#include "remapdlg.h" -#include "buttonutils.h" using namespace Opie::Core; class NoSortItem : public QListViewItem { public: NoSortItem ( QListView *lv, uint pos, const QString &str, const QCString &s1 = 0, const QCString &s2 = 0 ) : QListViewItem ( lv, str, s1, s2 ) { m_key = QString ( QChar ( 'a' + pos )); m_def = false; } - + void setDefault ( bool b ) { m_def = b; } - + virtual QString key ( int /*column*/, bool /*ascending*/ ) const { return m_key; } - - virtual void paintCell ( QPainter * p, const QColorGroup & cg, int column, int width, int align ) + + virtual void paintCell ( QPainter * p, const QColorGroup & cg, int column, int width, int align ) { if ( m_def ) { - QFont f ( listView ( )-> font ( )); - f. setBold ( true ); + QFont f ( listView ( )-> font ( )); + f. setBold ( true ); p-> setFont ( f ); } - QListViewItem::paintCell ( p, cg, column, width, align ); + QListViewItem::paintCell ( p, cg, column, width, align ); } - + private: QString m_key; bool m_def; }; RemapDlg::RemapDlg ( const Opie::Core::ODeviceButton *b, bool hold, QWidget *parent, const char *name ) : RemapDlgBase ( parent, name, true, WStyle_ContextHelp ) { setCaption ( tr( "%1 %2", "(hold|press) buttoname" ). arg( hold ? tr( "Held" ) : tr( "Pressed" )). arg ( b-> userText ( ))); m_current = 0; - + static const char * const def_channels [] = { "QPE/Application/", "QPE/Launcher", "QPE/System", "QPE/TaskBar", "QPE/", 0 }; w_channel-> insertStrList ((const char **) def_channels ); - + m_msg = hold ? b-> heldAction ( ) : b-> pressedAction ( ); m_msg_preset = hold ? b-> factoryPresetHeldAction ( ) : b-> factoryPresetPressedAction ( ); - + m_map_none = new NoSortItem ( w_list, 0, tr( "No mapping" )); m_map_preset = new NoSortItem ( w_list, 1, tr( "Default" ), m_msg_preset. channel ( ), m_msg_preset. message ( )); ((NoSortItem *) m_map_preset )-> setDefault ( true ); - + if (m_msg. channel ( ) == "ignore") { m_map_custom = new NoSortItem ( w_list, 2, tr( "Custom" ), m_msg_preset. channel ( ), m_msg_preset. message ( )); - + m_current = m_map_none; } else { m_map_custom = new NoSortItem ( w_list, 2, tr( "Custom" ), m_msg. channel ( ), m_msg. message ( )); m_current = m_map_custom; } - - QListViewItem *it = new NoSortItem ( w_list, 3, tr( "Actions" )); + + QListViewItem *it = new NoSortItem ( w_list, 3, tr( "Actions" )); ButtonUtils::inst ( )-> insertActions ( it ); it-> setOpen ( true ); - - m_map_show = new NoSortItem ( w_list, 4, tr( "Show" )); - + + m_map_show = new NoSortItem ( w_list, 4, tr( "Show" )); + w_list-> setCurrentItem ( m_current ); - + QTimer::singleShot ( 0, this, SLOT( delayedInit())); } RemapDlg::~RemapDlg ( ) { } void RemapDlg::delayedInit ( ) { bool b = w_list-> viewport ( )-> isUpdatesEnabled ( ); w_list-> viewport ( )-> setUpdatesEnabled ( false ); - + ButtonUtils::inst ( )-> insertAppLnks ( m_map_show ); - + w_list-> viewport ( )-> setUpdatesEnabled ( b ); - + m_map_show-> repaint ( ); } void RemapDlg::itemChanged ( QListViewItem *it ) { bool enabled = false; OQCopMessage m; - + m_current = it; if ( it == m_map_none ) { m_msg = m = OQCopMessage ( "ignore", 0 ); - qDebug ("***ignoring"); + odebug << "***ignoring" << oendl; } else if ( it == m_map_preset ) { m_msg = m = m_msg_preset; - qDebug ("***Preset"); + odebug << "***Preset" << oendl; } - else if ( it && !it-> childCount ( ) ) + else if ( it && !it-> childCount ( ) ) { - qDebug ("***Custom: %s %s ",it-> text ( 1 ). latin1 ( ), it-> text ( 2 ). latin1 ( )); + odebug << "***Custom: " << it-> text ( 1 ). latin1 ( ) << " " << it-> text ( 2 ). latin1 ( ) << oendl; enabled = ( it == m_map_custom ); m_msg = m = OQCopMessage ( it-> text ( 1 ). latin1 ( ), it-> text ( 2 ). latin1 ( )); } - + w_channel-> setEnabled ( enabled ); w_message-> setEnabled ( enabled ); - + w_channel-> setEditText ( m. channel ( )); //hack for if user has typed in a message, such as 'suspend()' -//so raise() is always present +//so raise() is always present if(m. message ( ) != "raise()") w_message->insertItem("raise()"); w_message-> setEditText ( m. message ( )); } void RemapDlg::textChanged ( const QString &str ) { if ( !m_current ) return; QComboBox *which = (QComboBox *) sender ( ); if ( which == w_channel ) m_current-> setText ( 1, str ); else if ( which == w_message ) m_current-> setText ( 2, str ); } OQCopMessage RemapDlg::message ( ) { //make sure to update message if typed in - itemChanged(w_list->currentItem()); + itemChanged(w_list->currentItem()); return m_msg; } diff --git a/core/settings/citytime/citytime.cpp b/core/settings/citytime/citytime.cpp index 721285d..d73bda1 100644 --- a/core/settings/citytime/citytime.cpp +++ b/core/settings/citytime/citytime.cpp @@ -1,279 +1,283 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ // changes by Maximilian Reiss <harlekin@handhelds.org> #include "zonemap.h" #include "citytime.h" +/* OPIE */ #include <qpe/qpeapplication.h> #include <qpe/config.h> #include <qpe/tzselect.h> #if !defined(QT_NO_COP) #include <qpe/qcopenvelope_qws.h> #endif +#include <opie2/odebug.h> +/* QT */ #include <qlabel.h> #include <qmessagebox.h> #include <qtoolbutton.h> #include <qlayout.h> +/* STD */ #include <stdlib.h> CityTime::CityTime( QWidget *parent, const char* name, WFlags fl ) : CityTimeBase( parent, name, fl ), strRealTz(0), bAdded(false) { Config config( "qpe" ); config.setGroup( "Time" ); bWhichClock = config.readBoolEntry( "AMPM", TRUE ); - qDebug( QString("%1").arg(bWhichClock) ); + odebug << QString("%1").arg(bWhichClock) << oendl; frmMap->changeClock( bWhichClock ); char *pEnv; pEnv = NULL; pEnv = getenv("TZ"); if ( pEnv ) strRealTz = pEnv; pEnv = NULL; pEnv = getenv("HOME"); if ( pEnv ) strHome = pEnv; // append the labels to their respective lists... listCities.setAutoDelete( true ); listTimes.setAutoDelete( true ); listCities.append( cmdCity1 ); listCities.append( cmdCity2 ); listCities.append( cmdCity3 ); listTimes.append( lblCTime1 ); listTimes.append( lblCTime2 ); listTimes.append( lblCTime3 ); // kludgy way of getting the screen size so we don't have to depend // on a resize event... QWidget *d = QApplication::desktop(); if ( d->width() < d->height() ) { // append for that 4 down look listCities.append( cmdCity4 ); listCities.append( cmdCity5 ); listCities.append( cmdCity6 ); listTimes.append( lblCTime4 ); listTimes.append( lblCTime5 ); listTimes.append( lblCTime6 ); lblCTime7->hide(); lblCTime8->hide(); lblCTime9->hide(); cmdCity7->hide(); cmdCity8->hide(); cmdCity9->hide(); } else { listCities.append( cmdCity7 ); listCities.append( cmdCity8 ); listCities.append( cmdCity9 ); listTimes.append( lblCTime7 ); listTimes.append( lblCTime8 ); listTimes.append( lblCTime9 ); lblCTime4->hide(); lblCTime5->hide(); lblCTime6->hide(); cmdCity4->hide(); cmdCity5->hide(); cmdCity6->hide(); } selWidget = frmMap->selectionWidget( this ); selWidget->hide(); CityTimeBaseLayout->addWidget( selWidget ); bAdded = true; readInTimes(); changed = FALSE; QObject::connect( qApp, SIGNAL( clockChanged(bool) ), this, SLOT( changeClock(bool) ) ); // now start the timer so we can update the time quickly every second timerEvent( 0 ); } CityTime::~CityTime() { if ( changed ) { - Config cfg("CityTime"); - cfg.setGroup("TimeZones"); - QListIterator<QToolButton> itCity( listCities ); - int i; - bool realTzWritten = FALSE; - for ( i = 0, itCity.toFirst(); i < CITIES; i++, ++itCity ) { - if ( !strCityTz[i].isNull() ) { - cfg.writeEntry("Zone"+QString::number(i), strCityTz[i]); - cfg.writeEntry("ZoneName"+QString::number(i), itCity.current()->text()); - if ( strCityTz[i] == strRealTz ) - realTzWritten = TRUE; - } - } - if ( realTzWritten ) { - cfg.removeEntry("Zone"+QString::number(CITIES)); - cfg.removeEntry("ZoneName"+QString::number(CITIES)); - } else { - cfg.writeEntry("Zone"+QString::number(CITIES), strRealTz); - if ( nameRealTz.isEmpty() ) { - int i = strRealTz.find( '/' ); - nameRealTz = strRealTz.mid( i+1 ); - } - cfg.writeEntry("ZoneName"+QString::number(CITIES), nameRealTz); - } - QCopEnvelope ( "QPE/System", "timeZoneListChange()" ); + Config cfg("CityTime"); + cfg.setGroup("TimeZones"); + QListIterator<QToolButton> itCity( listCities ); + int i; + bool realTzWritten = FALSE; + for ( i = 0, itCity.toFirst(); i < CITIES; i++, ++itCity ) { + if ( !strCityTz[i].isNull() ) { + cfg.writeEntry("Zone"+QString::number(i), strCityTz[i]); + cfg.writeEntry("ZoneName"+QString::number(i), itCity.current()->text()); + if ( strCityTz[i] == strRealTz ) + realTzWritten = TRUE; + } + } + if ( realTzWritten ) { + cfg.removeEntry("Zone"+QString::number(CITIES)); + cfg.removeEntry("ZoneName"+QString::number(CITIES)); + } else { + cfg.writeEntry("Zone"+QString::number(CITIES), strRealTz); + if ( nameRealTz.isEmpty() ) { + int i = strRealTz.find( '/' ); + nameRealTz = strRealTz.mid( i+1 ); + } + cfg.writeEntry("ZoneName"+QString::number(CITIES), nameRealTz); + } + QCopEnvelope ( "QPE/System", "timeZoneListChange()" ); - changed = FALSE; + changed = FALSE; } // restore the timezone, just in case we messed with it and // are destroyed at an inoppurtune moment if ( !strRealTz.isNull() ) { // this should be checked, but there is not much that can done at this //point if it fails setenv( "TZ", strRealTz, true ); } } void CityTime::timerEvent( QTimerEvent *e ) { if ( e ) - killTimer( timerId ); + killTimer( timerId ); // change the time again!! showTime(); int ms = 1000 - QTime::currentTime().msec(); timerId = startTimer( ms ); } void CityTime::mousePressEvent( QMouseEvent * ) { // DEBUG enable this to get a look at the zone information DEBUG // frmMap->showZones(); } void CityTime::showTime( void ) { int i; QListIterator<QLabel> itTime(listTimes); // traverse the list... for ( i = 0, itTime.toFirst(); i < CITIES; i++, ++itTime) { if ( !strCityTz[i].isNull() ) { if ( setenv( "TZ", strCityTz[i], true ) == 0 ) { - itTime.current()->setText( TimeString::shortTime( bWhichClock ) ); + itTime.current()->setText( TimeString::shortTime( bWhichClock ) ); } else { QMessageBox::critical( this, tr( "Time Changing" ), tr( "There was a problem setting timezone %1" ) .arg( QString::number( i + 1 ) ) ); } } } // done playing around... put it all back unsetenv( "TZ" ); if ( !strRealTz.isNull() ) { if ( setenv( "TZ", strRealTz, true ) != 0 ) { QMessageBox::critical( this, tr( "Restore Time Zone" ), tr( "There was a problem setting your timezone." "Your time may be wrong now..." ) ); } } } void CityTime::beginNewTz() { buttonWidget->hide(); frmMap->setFocus(); selWidget->show(); // CityTimeBaseLayout->addWidget( selWidget ); } void CityTime::slotNewTz( const QString & strNewCountry, const QString & strNewCity ) { // determine what to do based on what putton is pressed... QListIterator<QToolButton> itCity(listCities); int i; // go through the list and make adjustments based on which button is on for ( i = 0, itCity.toFirst(); itCity.current(), i < CITIES; i++, ++itCity ) { QToolButton *cmdTmp = itCity.current(); if ( cmdTmp->isOn() ) { strCityTz[i] = strNewCountry + strNewCity; QString s = strNewCity; cmdTmp->setText( s.replace( QRegExp("_"), " " ) ); cmdTmp->toggle(); // we can actually break, since there is only one button // that is ever pressed! - changed = TRUE; + changed = TRUE; break; } } showTime(); buttonWidget->show(); selWidget->hide(); } void CityTime::readInTimes( void ) { Config cfg("CityTime"); cfg.setGroup("TimeZones"); QListIterator<QToolButton> itCity( listCities ); int i=0; nameRealTz = QString::null; QString zn; for ( ; i < CITIES ; i++ ) { - zn = cfg.readEntry("Zone"+QString::number(i), QString::null); - if ( zn.isNull() ) - break; - QString nm = cfg.readEntry("ZoneName"+QString::number(i)); - strCityTz[i] = zn; - itCity.current()->setText(nm); - if ( zn == strRealTz ) - nameRealTz = nm; - ++itCity; + zn = cfg.readEntry("Zone"+QString::number(i), QString::null); + if ( zn.isNull() ) + break; + QString nm = cfg.readEntry("ZoneName"+QString::number(i)); + strCityTz[i] = zn; + itCity.current()->setText(nm); + if ( zn == strRealTz ) + nameRealTz = nm; + ++itCity; } if ( i == 0 ) { // write in our own in a shameless self promotion and some humor QStringList list = timezoneDefaults(); int i; QStringList::Iterator it = list.begin(); for ( i = 0, itCity.toFirst(); i < CITIES && itCity.current(); i++, ++itCity ) { strCityTz[i] = *it++; itCity.current()->setText( *it++ ); } } if ( nameRealTz.isEmpty() ) { - //remember the current time zone even if we don't have room - //to show it. - zn = cfg.readEntry("Zone"+QString::number(CITIES), QString::null); - if ( zn == strRealTz ) - nameRealTz = cfg.readEntry("ZoneName"+QString::number(CITIES)); - i++; + //remember the current time zone even if we don't have room + //to show it. + zn = cfg.readEntry("Zone"+QString::number(CITIES), QString::null); + if ( zn == strRealTz ) + nameRealTz = cfg.readEntry("ZoneName"+QString::number(CITIES)); + i++; } } void CityTime::changeClock( bool newClock ) { bWhichClock = newClock; showTime(); } diff --git a/core/settings/citytime/citytimebase.cpp b/core/settings/citytime/citytimebase.cpp index 323929b..77cb91d 100644 --- a/core/settings/citytime/citytimebase.cpp +++ b/core/settings/citytime/citytimebase.cpp @@ -1,70 +1,74 @@ // changes by Maximilian Reiss <harlekin@handhelds.org> #include "citytimebase.h" +#include "zonemap.h" + +/* OPIE */ +#include <opie2/odebug.h> +/* QT */ #include <qlabel.h> #include <qtoolbutton.h> -#include "zonemap.h" #include <qlayout.h> #include <qwhatsthis.h> /* * Constructs a CityTimeBase which is a child of 'parent', with the * name 'name' and widget flags set to 'f' */ CityTimeBase::CityTimeBase( QWidget* parent, const char* name, WFlags ) : QWidget( parent, name, WStyle_ContextHelp ) { if ( !name ) - setName( "CityTimeBase" ); + setName( "CityTimeBase" ); setCaption( tr( "City Time" ) ); CityTimeBaseLayout = new QVBoxLayout( this ); CityTimeBaseLayout->setSpacing( 3 ); CityTimeBaseLayout->setMargin( 0 ); frmMap = new ZoneMap( this, "frmMap" ); frmMap->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)7, frmMap->sizePolicy().hasHeightForWidth() ) ); CityTimeBaseLayout->addWidget( frmMap ); buttonWidget = new QWidget( this ); QWhatsThis::add( buttonWidget, tr( "Click on one of the set cities to replace it" ) ); Layout2 = new QGridLayout( buttonWidget ); Layout2->setSpacing( 3 ); Layout2->setMargin( 4 ); cmdCity7 = new QToolButton( buttonWidget, "cmdCity7" ); cmdCity7->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)1, cmdCity7->sizePolicy().hasHeightForWidth() ) ); QFont cmdCity7_font( cmdCity7->font() ); cmdCity7_font.setBold( TRUE ); cmdCity7->setFont( cmdCity7_font ); cmdCity7->setFocusPolicy( QToolButton::TabFocus ); cmdCity7->setText( tr( "" ) ); cmdCity7->setToggleButton( TRUE ); cmdCity7->setToggleButton( TRUE ); Layout2->addWidget( cmdCity7, 0, 2 ); lblCTime9 = new QLabel( buttonWidget, "lblCTime9" ); lblCTime9->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)1, lblCTime9->sizePolicy().hasHeightForWidth() ) ); QFont lblCTime9_font( lblCTime9->font() ); lblCTime9_font.setPointSize( 10 ); lblCTime9->setFont( lblCTime9_font ); lblCTime9->setText( tr( "" ) ); lblCTime9->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) ); Layout2->addWidget( lblCTime9, 2, 3 ); cmdCity8 = new QToolButton( buttonWidget, "cmdCity8" ); cmdCity8->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)1, cmdCity8->sizePolicy().hasHeightForWidth() ) ); QFont cmdCity8_font( cmdCity8->font() ); cmdCity8_font.setBold( TRUE ); cmdCity8->setFont( cmdCity8_font ); cmdCity8->setFocusPolicy( QToolButton::TabFocus ); cmdCity8->setText( tr( "" ) ); cmdCity8->setToggleButton( TRUE ); cmdCity8->setToggleButton( TRUE ); Layout2->addWidget( cmdCity8, 1, 2 ); @@ -296,116 +300,116 @@ CityTimeBase::CityTimeBase( QWidget* parent, const char* name, WFlags ) connect( cmdCity9, SIGNAL( toggled(bool) ), cmdCity7, SLOT( setDisabled(bool) ) ); connect( cmdCity9, SIGNAL( toggled(bool) ), cmdCity8, SLOT( setDisabled(bool) ) ); connect( cmdCity1, SIGNAL( toggled(bool) ), cmdCity9, SLOT( setDisabled(bool) ) ); connect( cmdCity2, SIGNAL( toggled(bool) ), cmdCity9, SLOT( setDisabled(bool) ) ); connect( cmdCity3, SIGNAL( toggled(bool) ), cmdCity9, SLOT( setDisabled(bool) ) ); connect( cmdCity4, SIGNAL( toggled(bool) ), cmdCity9, SLOT( setDisabled(bool) ) ); connect( cmdCity5, SIGNAL( toggled(bool) ), cmdCity9, SLOT( setDisabled(bool) ) ); connect( cmdCity7, SIGNAL( toggled(bool) ), cmdCity9, SLOT( setDisabled(bool) ) ); connect( cmdCity8, SIGNAL( toggled(bool) ), cmdCity9, SLOT( setDisabled(bool) ) ); connect( cmdCity9, SIGNAL( toggled(bool) ), cmdCity2, SLOT( setDisabled(bool) ) ); connect( cmdCity1, SIGNAL( toggled(bool) ), this, SLOT( beginNewTz() ) ); connect( cmdCity2, SIGNAL( toggled(bool) ), this, SLOT( beginNewTz() ) ); connect( cmdCity7, SIGNAL( toggled(bool) ), this, SLOT( beginNewTz() ) ); connect( cmdCity3, SIGNAL( toggled(bool) ), this, SLOT( beginNewTz() ) ); connect( cmdCity4, SIGNAL( toggled(bool) ), this, SLOT( beginNewTz() ) ); connect( cmdCity5, SIGNAL( toggled(bool) ), this, SLOT( beginNewTz() ) ); connect( cmdCity6, SIGNAL( toggled(bool) ), this, SLOT( beginNewTz() ) ); connect( cmdCity8, SIGNAL( toggled(bool) ), this, SLOT( beginNewTz() ) ); connect( cmdCity9, SIGNAL( toggled(bool) ), this, SLOT( beginNewTz() ) ); // tab order setTabOrder( cmdCity1, cmdCity2 ); setTabOrder( cmdCity2, cmdCity3 ); setTabOrder( cmdCity3, cmdCity4 ); setTabOrder( cmdCity4, cmdCity5 ); setTabOrder( cmdCity5, cmdCity6 ); setTabOrder( cmdCity6, cmdCity7 ); setTabOrder( cmdCity7, cmdCity8 ); setTabOrder( cmdCity8, cmdCity9 ); setTabOrder( cmdCity9, frmMap ); } /* * Destroys the object and frees any allocated resources */ CityTimeBase::~CityTimeBase() { // no need to delete child widgets, Qt does it all for us } /* * Main event handler. Reimplemented to handle application * font changes */ bool CityTimeBase::event( QEvent* ev ) { bool ret = QWidget::event( ev ); if ( ev->type() == QEvent::ApplicationFontChange ) { - QFont cmdCity7_font( cmdCity7->font() ); - cmdCity7_font.setBold( TRUE ); - cmdCity7->setFont( cmdCity7_font ); - QFont lblCTime9_font( lblCTime9->font() ); - lblCTime9_font.setPointSize( 10 ); - lblCTime9->setFont( lblCTime9_font ); - QFont cmdCity8_font( cmdCity8->font() ); - cmdCity8_font.setBold( TRUE ); - cmdCity8->setFont( cmdCity8_font ); - QFont cmdCity2_font( cmdCity2->font() ); - cmdCity2_font.setBold( TRUE ); - cmdCity2->setFont( cmdCity2_font ); - QFont lblCTime6_font( lblCTime6->font() ); - lblCTime6_font.setPointSize( 10 ); - lblCTime6->setFont( lblCTime6_font ); - QFont cmdCity6_font( cmdCity6->font() ); - cmdCity6_font.setBold( TRUE ); - cmdCity6->setFont( cmdCity6_font ); - QFont cmdCity4_font( cmdCity4->font() ); - cmdCity4_font.setBold( TRUE ); - cmdCity4->setFont( cmdCity4_font ); - QFont lblCTime5_font( lblCTime5->font() ); - lblCTime5_font.setPointSize( 10 ); - lblCTime5->setFont( lblCTime5_font ); - QFont lblCTime2_font( lblCTime2->font() ); - lblCTime2_font.setPointSize( 10 ); - lblCTime2->setFont( lblCTime2_font ); - QFont lblCTime1_font( lblCTime1->font() ); - lblCTime1_font.setPointSize( 10 ); - lblCTime1->setFont( lblCTime1_font ); - QFont cmdCity3_font( cmdCity3->font() ); - cmdCity3_font.setBold( TRUE ); - cmdCity3->setFont( cmdCity3_font ); - QFont lblCTime8_font( lblCTime8->font() ); - lblCTime8_font.setPointSize( 10 ); - lblCTime8->setFont( lblCTime8_font ); - QFont cmdCity1_font( cmdCity1->font() ); - cmdCity1_font.setBold( TRUE ); - cmdCity1->setFont( cmdCity1_font ); - QFont lblCTime7_font( lblCTime7->font() ); - lblCTime7_font.setPointSize( 10 ); - lblCTime7->setFont( lblCTime7_font ); - QFont lblCTime4_font( lblCTime4->font() ); - lblCTime4_font.setPointSize( 10 ); - lblCTime4->setFont( lblCTime4_font ); - QFont cmdCity5_font( cmdCity5->font() ); - cmdCity5_font.setBold( TRUE ); - cmdCity5->setFont( cmdCity5_font ); - QFont lblCTime3_font( lblCTime3->font() ); - lblCTime3_font.setPointSize( 10 ); - lblCTime3->setFont( lblCTime3_font ); - QFont cmdCity9_font( cmdCity9->font() ); - cmdCity9_font.setBold( TRUE ); - cmdCity9->setFont( cmdCity9_font ); + QFont cmdCity7_font( cmdCity7->font() ); + cmdCity7_font.setBold( TRUE ); + cmdCity7->setFont( cmdCity7_font ); + QFont lblCTime9_font( lblCTime9->font() ); + lblCTime9_font.setPointSize( 10 ); + lblCTime9->setFont( lblCTime9_font ); + QFont cmdCity8_font( cmdCity8->font() ); + cmdCity8_font.setBold( TRUE ); + cmdCity8->setFont( cmdCity8_font ); + QFont cmdCity2_font( cmdCity2->font() ); + cmdCity2_font.setBold( TRUE ); + cmdCity2->setFont( cmdCity2_font ); + QFont lblCTime6_font( lblCTime6->font() ); + lblCTime6_font.setPointSize( 10 ); + lblCTime6->setFont( lblCTime6_font ); + QFont cmdCity6_font( cmdCity6->font() ); + cmdCity6_font.setBold( TRUE ); + cmdCity6->setFont( cmdCity6_font ); + QFont cmdCity4_font( cmdCity4->font() ); + cmdCity4_font.setBold( TRUE ); + cmdCity4->setFont( cmdCity4_font ); + QFont lblCTime5_font( lblCTime5->font() ); + lblCTime5_font.setPointSize( 10 ); + lblCTime5->setFont( lblCTime5_font ); + QFont lblCTime2_font( lblCTime2->font() ); + lblCTime2_font.setPointSize( 10 ); + lblCTime2->setFont( lblCTime2_font ); + QFont lblCTime1_font( lblCTime1->font() ); + lblCTime1_font.setPointSize( 10 ); + lblCTime1->setFont( lblCTime1_font ); + QFont cmdCity3_font( cmdCity3->font() ); + cmdCity3_font.setBold( TRUE ); + cmdCity3->setFont( cmdCity3_font ); + QFont lblCTime8_font( lblCTime8->font() ); + lblCTime8_font.setPointSize( 10 ); + lblCTime8->setFont( lblCTime8_font ); + QFont cmdCity1_font( cmdCity1->font() ); + cmdCity1_font.setBold( TRUE ); + cmdCity1->setFont( cmdCity1_font ); + QFont lblCTime7_font( lblCTime7->font() ); + lblCTime7_font.setPointSize( 10 ); + lblCTime7->setFont( lblCTime7_font ); + QFont lblCTime4_font( lblCTime4->font() ); + lblCTime4_font.setPointSize( 10 ); + lblCTime4->setFont( lblCTime4_font ); + QFont cmdCity5_font( cmdCity5->font() ); + cmdCity5_font.setBold( TRUE ); + cmdCity5->setFont( cmdCity5_font ); + QFont lblCTime3_font( lblCTime3->font() ); + lblCTime3_font.setPointSize( 10 ); + lblCTime3->setFont( lblCTime3_font ); + QFont cmdCity9_font( cmdCity9->font() ); + cmdCity9_font.setBold( TRUE ); + cmdCity9->setFont( cmdCity9_font ); } return ret; } void CityTimeBase::beginNewTz() { - qWarning( "CityTimeBase::beginNewTz(): Not implemented yet!" ); + owarn << "CityTimeBase::beginNewTz(): Not implemented yet!" << oendl; } void CityTimeBase::slotNewTz(const QString &, const QString &) { - qWarning( "CityTimeBase::slotNewTz(const QString &, const QString &): Not implemented yet!" ); + owarn << "CityTimeBase::slotNewTz(const QString &, const QString &): Not implemented yet!" << oendl; } diff --git a/core/settings/citytime/zonemap.cpp b/core/settings/citytime/zonemap.cpp index b6843d2..e4a25ef 100644 --- a/core/settings/citytime/zonemap.cpp +++ b/core/settings/citytime/zonemap.cpp @@ -1,724 +1,728 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ // changes by Maximilian Reiss <harlekin@handhelds.org> #include "sun.h" #include "zonemap.h" +/* OPIE */ #include <qpe/resource.h> #include <qpe/qpeapplication.h> +#include <opie2/odebug.h> +/* QT */ #include <qfile.h> #include <qlabel.h> #include <qmessagebox.h> #include <qtextstream.h> #include <qtimer.h> #include <qtoolbutton.h> #include <qlayout.h> #include <qhbox.h> #include <qlistview.h> #include <qwhatsthis.h> +/* STD */ #include <limits.h> // the map file... static const char strZONEINFO[] = "/usr/share/zoneinfo/zone.tab"; static const char strMAP[] = "citytime/simple_grid_400"; // the maximum distance we'll allow the pointer to be away from a city // and still show the city's time static const int iTHRESHOLD = 50000; // The label offset (how far away from pointer) static const int iLABELOFFSET = 8; // the size of the dot to draw, and where to start it static const int iCITYSIZE = 3; const int iCITYOFFSET = 2; // the darkening function static inline void darken( QImage *pImage, int start, int stop, int row ); static void dayNight( QImage *pImage ); ZoneField::ZoneField( const QString& strLine ) { // make a bunch of RegExp's to match the data from the line - QRegExp regCoord( "[-+][0-9]+" ); // the latitude + QRegExp regCoord( "[-+][0-9]+" ); // the latitude QRegExp regCountry( "[A-Za-z]+/" ); // the country (not good enough) QRegExp regCity( "[A-Za-z_-]*" ); // the city int iStart, - iStop, + iStop, iLen, tmp; QString strTmp; // we should be able to assume that the country code is always the first // two chars, so just grap them and let it go... strCountryCode = strLine.left( 2 ); iStart = regCoord.match( strLine, 0, &iLen ); if ( iStart >= 0 ) { - strTmp = strLine.mid( iStart, iLen ); - tmp = strTmp.toInt(); - // okay, there are two versions of the format, make a decision based on - // the size... - // Oh BTW, we are storing everything in seconds! - if ( iLen < 7 ) { - _y = tmp / 100; - _y *= 60; - _y += tmp % 100; - _y *= 60; - } else { - _y = tmp / 10000; - _y *= 60; - tmp %= 10000; - _y += tmp / 100; - _y *= 60; - tmp %= 100; - _y += tmp; - } + strTmp = strLine.mid( iStart, iLen ); + tmp = strTmp.toInt(); + // okay, there are two versions of the format, make a decision based on + // the size... + // Oh BTW, we are storing everything in seconds! + if ( iLen < 7 ) { + _y = tmp / 100; + _y *= 60; + _y += tmp % 100; + _y *= 60; + } else { + _y = tmp / 10000; + _y *= 60; + tmp %= 10000; + _y += tmp / 100; + _y *= 60; + tmp %= 100; + _y += tmp; + } } iStart = regCoord.match( strLine, iStart + iLen, &iLen ); if ( iStart >= 0 ) { - strTmp = strLine.mid( iStart, iLen ); - tmp = strTmp.toInt(); - if ( iLen < 8 ) { - _x = tmp / 100; - _x *= 60; - _x += tmp % 100; - _x *= 60; - } else { - _x = tmp / 10000; - _x *= 60; - tmp %= 10000; - _x += tmp / 100; - _x *= 60; - tmp %= 100; - _x += tmp; - } + strTmp = strLine.mid( iStart, iLen ); + tmp = strTmp.toInt(); + if ( iLen < 8 ) { + _x = tmp / 100; + _x *= 60; + _x += tmp % 100; + _x *= 60; + } else { + _x = tmp / 10000; + _x *= 60; + tmp %= 10000; + _x += tmp / 100; + _x *= 60; + tmp %= 100; + _x += tmp; + } } iStart = regCountry.match( strLine, 0, &iLen ); // help with the shortcoming in 2.x regexp... iStop = strLine.findRev( '/' ); if ( iStart >= 0 ) { - iLen = (iStop - iStart) + 1; - strCountry = strLine.mid( iStart, iLen ); + iLen = (iStop - iStart) + 1; + strCountry = strLine.mid( iStart, iLen ); } // now match the city... iStart = regCity.match( strLine, iStart + iLen, &iLen ); if ( iStart >= 0 ) { - strCity = strLine.mid( iStart, iLen ); + strCity = strLine.mid( iStart, iLen ); } } void ZoneField::showStructure( void ) const { - qDebug( "Country: %s", strCountry.latin1() ); - qDebug( "City: %s", strCity.latin1() ); - qDebug( "x: %d", _x ); - qDebug( "y: %d\n", _y ); + odebug << "Country: " << strCountry << "" << oendl; + odebug << "City: " << strCity << "" << oendl; + odebug << "x: " << _x << "" << oendl; + odebug << "y: " << _y << "\n" << oendl; } ZoneMap::ZoneMap( QWidget *parent, const char* name ) : QScrollView( parent, name ), pLast( 0 ), pRepaint( 0 ), ox( 0 ), oy( 0 ), drawableW( -1 ), drawableH( -1 ), bZoom( FALSE ), bIllum( TRUE ), cursor( 0 ) { viewport()->setFocusPolicy( StrongFocus ); // set mouse tracking so we can use the mouse move event zones.setAutoDelete( true ); // get the map loaded // just set the current image to point pixCurr = new QPixmap(); QPixmap pixZoom = Resource::loadPixmap( "mag" ); cmdZoom = new QToolButton( this, "Zoom command" ); cmdZoom->setPixmap( pixZoom ); cmdZoom->setToggleButton( true ); cmdZoom->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0, (QSizePolicy::SizeType)0, cmdZoom->sizePolicy().hasHeightForWidth() ) ); cmdZoom->setMaximumSize( cmdZoom->sizeHint() ); // probably don't need this, but just in case... cmdZoom->move( width() - cmdZoom->width(), height() - cmdZoom->height() ); lblCity = new QLabel( tr( "CITY" ), this, "City Label" ); lblCity->setMinimumSize( lblCity->sizeHint() ); lblCity->setFrameStyle( QFrame::Plain | QFrame::Box ); lblCity->setBackgroundColor( yellow ); lblCity->hide(); // A timer to make sure the label gets hidden tHide = new QTimer( this, "Label Timer" ); QObject::connect( tHide, SIGNAL( timeout() ), lblCity, SLOT( hide() ) ); QObject::connect( tHide, SIGNAL( timeout() ), this, SLOT( slotRedraw() ) ); QTimer *tUpdate = new QTimer( this, "Update Timer" ); QObject::connect( tUpdate, SIGNAL( timeout() ), this, SLOT( slotUpdate() ) ); QObject::connect( qApp, SIGNAL( timeChanged() ), this, SLOT( slotUpdate() ) ); QObject::connect( cmdZoom, SIGNAL( toggled(bool) ), this, SLOT( slotZoom(bool) ) ); QObject::connect( &norm, SIGNAL( signalNewPoint(const QPoint&) ), this, SLOT( slotFindCity(const QPoint&) ) ); QObject::connect( qApp, SIGNAL( clockChanged(bool) ), this, SLOT( changeClock(bool) ) ); // update the sun's movement every 5 minutes tUpdate->start( 5 * 60 * 1000 ); // May as well read in the timezone information too... readZones(); } ZoneMap::~ZoneMap() { } void ZoneMap::readZones( void ) { QFile fZone( strZONEINFO ); if ( !fZone.open( IO_ReadOnly ) ) { - QMessageBox::warning (this, - tr( "Unable to Find Timezone Info" ), - tr( "<p>Unable to find any timezone information in %1" ) - .arg( strZONEINFO )); - exit(-1); + QMessageBox::warning (this, + tr( "Unable to Find Timezone Info" ), + tr( "<p>Unable to find any timezone information in %1" ) + .arg( strZONEINFO )); + exit(-1); } else { - QTextStream tZone( &fZone ); - while ( !tZone.atEnd() ) { - QString strLine = tZone.readLine(); - // only pass on lines that aren't comments - if ( strLine[0] != '#' ) { - zones.append( new ZoneField( strLine ) ); - } - } - fZone.close(); + QTextStream tZone( &fZone ); + while ( !tZone.atEnd() ) { + QString strLine = tZone.readLine(); + // only pass on lines that aren't comments + if ( strLine[0] != '#' ) { + zones.append( new ZoneField( strLine ) ); + } + } + fZone.close(); } } void ZoneMap::viewportMousePressEvent( QMouseEvent* event ) { // add the mouse event into the normalizer, and get the average, // pass it along slotRedraw(); norm.start(); norm.addEvent( event->pos() ); } void ZoneMap::viewportMouseMoveEvent( QMouseEvent* event ) { norm.addEvent( event->pos() ); } void ZoneMap::viewportMouseReleaseEvent( QMouseEvent* ) { // get the averaged points in case a timeout hasn't occurred, // more for "mouse clicks" norm.stop(); if ( pLast != NULL ) { - emit signalTz( pLast->country(), pLast->city() ); - pLast = NULL; + emit signalTz( pLast->country(), pLast->city() ); + pLast = NULL; } tHide->start( 2000, true ); } void ZoneMap::keyPressEvent( QKeyEvent *ke ) { switch ( ke->key() ) { - case Key_Left: - case Key_Right: - case Key_Up: - case Key_Down: { - tHide->stop(); - if ( !cursor ) - slotFindCity( QPoint( contentsWidth(), contentsHeight() ) / 2 ); - ZoneField *city = findCityNear( cursor, ke->key() ); - if ( city ) { - cursor = city; - int tmpx, tmpy; - zoneToWin( cursor->x(), cursor->y(), tmpx, tmpy ); - ensureVisible( tmpx, tmpy ); - showCity( cursor ); - tHide->start( 3000, true ); - } - } - break; - - case Key_Space: - case Key_Enter: - case Key_Return: - if ( cursor ) { - emit signalTz( cursor->country(), cursor->city() ); - tHide->start( 0, true ); - } - break; + case Key_Left: + case Key_Right: + case Key_Up: + case Key_Down: { + tHide->stop(); + if ( !cursor ) + slotFindCity( QPoint( contentsWidth(), contentsHeight() ) / 2 ); + ZoneField *city = findCityNear( cursor, ke->key() ); + if ( city ) { + cursor = city; + int tmpx, tmpy; + zoneToWin( cursor->x(), cursor->y(), tmpx, tmpy ); + ensureVisible( tmpx, tmpy ); + showCity( cursor ); + tHide->start( 3000, true ); + } + } + break; + + case Key_Space: + case Key_Enter: + case Key_Return: + if ( cursor ) { + emit signalTz( cursor->country(), cursor->city() ); + tHide->start( 0, true ); + } + break; } } ZoneField *ZoneMap::findCityNear( ZoneField *city, int key ) { ZoneField *pZone; ZoneField *pClosest = 0; long ddist = LONG_MAX; QListIterator<ZoneField> it( zones ); for (; it.current(); ++it) { - pZone = it.current(); - long dx = (pZone->x() - city->x())/100; - long dy = (pZone->y() - city->y())/100; - switch ( key ) { - case Key_Right: - case Key_Left: - if ( key == Key_Left ) - dx = -dx; - if ( dx > 0 ) { - long dist = QABS(dy)*4 + dx; - if ( dist < ddist ) { - ddist = dist; - pClosest = pZone; - } - } - break; - case Key_Down: - case Key_Up: - if ( key == Key_Down ) - dy = -dy; - if ( dy > 0 ) { - long dist = QABS(dx)*4 + dy; - if ( dist < ddist ) { - ddist = dist; - pClosest = pZone; - } - } - break; - } + pZone = it.current(); + long dx = (pZone->x() - city->x())/100; + long dy = (pZone->y() - city->y())/100; + switch ( key ) { + case Key_Right: + case Key_Left: + if ( key == Key_Left ) + dx = -dx; + if ( dx > 0 ) { + long dist = QABS(dy)*4 + dx; + if ( dist < ddist ) { + ddist = dist; + pClosest = pZone; + } + } + break; + case Key_Down: + case Key_Up: + if ( key == Key_Down ) + dy = -dy; + if ( dy > 0 ) { + long dist = QABS(dx)*4 + dy; + if ( dist < ddist ) { + ddist = dist; + pClosest = pZone; + } + } + break; + } } return pClosest; } void ZoneMap::slotFindCity( const QPoint &pos ) { lblCity->hide(); // given coordinates on the screen find the closest city and display the // label close to it int tmpx, tmpy, x, y; long lDistance, lClosest; ZoneField *pZone, *pClosest; if ( tHide->isActive() ) { tHide->stop(); } viewportToContents(pos.x(), pos.y(), tmpx, tmpy); winToZone( tmpx, tmpy, x, y ); // Find city alogorithim: start out at an (near) infinite distance away and // then find the closest city, (similar to the Z-buffer technique, I guess) // the only problem is that this is all done with doubles, but I don't know // another way to do it at the moment. Another problem is a linked list is // used obviously something indexed would help QListIterator<ZoneField> it( zones ); pClosest = 0; lClosest = LONG_MAX; for (; it.current(); ++it) { - pZone = it.current(); - // use the manhattenLength, a good enough of an appoximation here - lDistance = QABS( x - pZone->x() ) + QABS( y - pZone->y() ); - // first to zero wins! - if ( lDistance < lClosest ) { - lClosest = lDistance; - pClosest = pZone; - } + pZone = it.current(); + // use the manhattenLength, a good enough of an appoximation here + lDistance = QABS( x - pZone->x() ) + QABS( y - pZone->y() ); + // first to zero wins! + if ( lDistance < lClosest ) { + lClosest = lDistance; + pClosest = pZone; + } } // Okay, we found the closest city, but it might still be too far away. if ( lClosest <= iTHRESHOLD ) { - showCity( pClosest ); - cursor = pClosest; + showCity( pClosest ); + cursor = pClosest; } } void ZoneMap::showCity( ZoneField *city ) { pLast = city; // we'll use city and country a couple of times, get them to save some // time QString strCity = pLast->city(); QString strCountry = pLast->country(); // Display the time at this location by setting the environment timezone // getting the current time [there] and then swapping back the variable // so no one notices... QString strSave; char *p = getenv( "TZ" ); if ( p ) { - strSave = p; + strSave = p; } // set the timezone :) setenv( "TZ", strCountry + strCity, true ); lblCity->setText( strCity.replace( QRegExp("_"), " ") + "\n" + - TimeString::shortTime( ampm ) ); + TimeString::shortTime( ampm ) ); lblCity->setMinimumSize( lblCity->sizeHint() ); // undue our damage... unsetenv( "TZ" ); if ( p ) - setenv( "TZ", strSave, true ); + setenv( "TZ", strSave, true ); // Now decide where to move the label, x & y can be reused int tmpx, tmpy, x, y; zoneToWin( pLast->x(), pLast->y(), tmpx, tmpy ); contentsToViewport(tmpx, tmpy, x, y); if ( lblCity->width() > drawableW - x ) { - // oops... try putting it on the right - x = x - lblCity->width() - iLABELOFFSET; + // oops... try putting it on the right + x = x - lblCity->width() - iLABELOFFSET; } else { - // the default... - x += iLABELOFFSET; + // the default... + x += iLABELOFFSET; } if ( lblCity->height() > drawableH - y ) { - // move it up... - y = y - lblCity->height() - iLABELOFFSET; + // move it up... + y = y - lblCity->height() - iLABELOFFSET; } else if ( y < 0 ) { - // the city is actually off the screen... - // this only happens on the a zoom when you are near the top, - // a quick workaround.. - y = iLABELOFFSET; + // the city is actually off the screen... + // this only happens on the a zoom when you are near the top, + // a quick workaround.. + y = iLABELOFFSET; } else { - // the default - y += iLABELOFFSET; + // the default + y += iLABELOFFSET; } // draw in the city and the label if ( pRepaint ) { - int repx, - repy; - zoneToWin( pRepaint->x(), pRepaint->y(), repx, repy ); - updateContents( repx - iCITYOFFSET, repy - iCITYOFFSET, - iCITYSIZE, iCITYSIZE ); + int repx, + repy; + zoneToWin( pRepaint->x(), pRepaint->y(), repx, repy ); + updateContents( repx - iCITYOFFSET, repy - iCITYOFFSET, + iCITYSIZE, iCITYSIZE ); } updateContents( tmpx - iCITYOFFSET, tmpy - iCITYOFFSET, iCITYSIZE, - iCITYSIZE ); + iCITYSIZE ); pRepaint = pLast; lblCity->move( x, y ); lblCity->show(); } void ZoneMap::resizeEvent( QResizeEvent *e ) { // keep the zoom button down in the corner QSize _size = e->size(); cmdZoom->move( _size.width() - cmdZoom->width(), _size.height() - cmdZoom->height() ); if ( !bZoom ) { - drawableW = width() - 2 * frameWidth(); - drawableH = height() - 2 * frameWidth(); - makeMap( drawableW, drawableH ); - resizeContents( drawableW, drawableH ); + drawableW = width() - 2 * frameWidth(); + drawableH = height() - 2 * frameWidth(); + makeMap( drawableW, drawableH ); + resizeContents( drawableW, drawableH ); } } void ZoneMap::showZones( void ) const { // go through the zones in the list and just display the values... QListIterator<ZoneField> itZone( zones ); for ( itZone.toFirst(); itZone.current(); ++itZone ) { - ZoneField *pZone = itZone.current(); - pZone->showStructure(); + ZoneField *pZone = itZone.current(); + pZone->showStructure(); } } QWidget* ZoneMap::selectionWidget( QWidget *parent) { QWidget *returnWidget = new QWidget( parent ); QVBoxLayout *layout = new QVBoxLayout( returnWidget ); QHBox *hBox = new QHBox( returnWidget ); QListView *continentView = new QListView( hBox ); continentView->addColumn( tr("Continent") ); QWhatsThis::add( continentView, tr("Select a continent/country here, then select a city") ); connect ( continentView, SIGNAL( clicked(QListViewItem*) ), this, SLOT( slotGetCities(QListViewItem*) ) ); QStringList continentList; QListIterator<ZoneField> itZone( zones ); for ( itZone.toFirst(); itZone.current(); ++itZone ) { - ZoneField *pZone = itZone.current(); + ZoneField *pZone = itZone.current(); if ( continentList.contains( pZone->country() ) == 0 ) { QString name; QListViewItem *item; if ( !(pZone->country().length() > 24) ) { name = pZone->country().left(pZone->country().length()-1 ); } else { name = pZone->country().left( 24 ); } item = new QListViewItem( continentView, name, pZone->country() ); continentList.append( pZone->country() ); } } cityView = new QListView( hBox ); cityView->addColumn( tr("City") ); layout->addWidget( hBox ); return returnWidget; } void ZoneMap::slotGetCities( QListViewItem * contItem) { cityView->clear(); selectedCont = contItem->text( 1 ); QListIterator<ZoneField> itZone( zones ); for ( itZone.toFirst(); itZone.current(); ++itZone ) { - ZoneField *pZone = itZone.current(); + ZoneField *pZone = itZone.current(); if ( pZone->country() == contItem->text( 1 ) ) { QListViewItem *item; item = new QListViewItem( cityView, pZone->city() ); connect ( cityView, SIGNAL( clicked(QListViewItem*) ), this, SLOT( slotCitySelected(QListViewItem*) ) ); } } } void ZoneMap::slotCitySelected( QListViewItem *cityItem ) { if ( cityItem ) { emit signalTz( selectedCont, cityItem->text( 0 ) ); } } void ZoneMap::drawCities( QPainter *p ) { int x, y, j; // draw in the cities // for testing only as when you put it // on the small screen it looks awful and not to mention useless p->setPen( red ); QListIterator<ZoneField> itZone( zones ); for ( itZone.toFirst(), j = 0; itZone.current(); ++itZone, j++ ) { - ZoneField *pZone = itZone.current(); - zoneToWin( pZone->x(), pZone->y(), x, y ); - if ( x > wImg ) - x = x - wImg; - p->drawRect( x - iCITYOFFSET, y - iCITYOFFSET, iCITYSIZE, iCITYSIZE); + ZoneField *pZone = itZone.current(); + zoneToWin( pZone->x(), pZone->y(), x, y ); + if ( x > wImg ) + x = x - wImg; + p->drawRect( x - iCITYOFFSET, y - iCITYOFFSET, iCITYSIZE, iCITYSIZE); } } static void dayNight(QImage *pImage) { // create a mask the functions from sun.h double dJulian, dSunRad, dSunDecl, dSunRadius, dSunLong; int wImage = pImage->width(), hImage = pImage->height(), iStart, iStop, iMid, relw, i; short wtab[ wImage ]; time_t tCurrent; struct tm *pTm; // get the position of the sun bassed on our current time... tCurrent = time( NULL ); pTm = gmtime( &tCurrent ); dJulian = jtime( pTm ); sunpos( dJulian, 0, &dSunRad, &dSunDecl, &dSunRadius, &dSunLong ); // now get the projected illumination projillum( wtab, wImage, hImage, dSunDecl ); relw = wImage - int( wImage * 0.0275 ); // draw the map, keeping in mind that we may go too far off the map... iMid = ( relw * ( 24*60 - pTm->tm_hour * 60 - pTm->tm_min ) ) / ( 24*60 ); for ( i = 0; i < hImage; i++ ) { - if ( wtab[i] > 0 ) { - iStart = iMid - wtab[i]; - iStop = iMid + wtab[i]; - if ( iStart < 0 ) { - darken( pImage, iStop, wImage + iStart, i ); - } else if ( iStop > wImage ) { - darken( pImage, iStop - wImage, iStart, i ); - } else { - darken( pImage, 0, iStart, i ); - darken( pImage, iStop, wImage, i ); - } - } else { - darken( pImage, 0, wImage, i ); - } + if ( wtab[i] > 0 ) { + iStart = iMid - wtab[i]; + iStop = iMid + wtab[i]; + if ( iStart < 0 ) { + darken( pImage, iStop, wImage + iStart, i ); + } else if ( iStop > wImage ) { + darken( pImage, iStop - wImage, iStart, i ); + } else { + darken( pImage, 0, iStart, i ); + darken( pImage, iStop, wImage, i ); + } + } else { + darken( pImage, 0, wImage, i ); + } } } static inline void darken( QImage *pImage, int start, int stop, int row ) { int colors, j; uchar *p; // assume that the image is similar to the one we have... colors = pImage->numColors() / 2; p = pImage->scanLine( row ); for ( j = start; j <= stop; j++ ) { - if ( p[j] < colors ) - p[j] += colors; + if ( p[j] < colors ) + p[j] += colors; } } void ZoneMap::makeMap( int w, int h ) { QImage imgOrig = Resource::loadImage( strMAP ); if ( imgOrig.isNull() ) { - QMessageBox::warning( this, - tr( "Couldn't Find Map" ), - tr( "<p>Couldn't load map: %1, exiting") + QMessageBox::warning( this, + tr( "Couldn't Find Map" ), + tr( "<p>Couldn't load map: %1, exiting") .arg( strMAP ) ); - exit(-1); + exit(-1); } // set up the color table for darkening... imgOrig = imgOrig.convertDepth( 8 ); int numColors = imgOrig.numColors(); // double the colors imgOrig.setNumColors( 2 * numColors ); // darken the new ones... for ( int i = 0; i < numColors; i++ ) { - QRgb rgb = imgOrig.color( i ); - imgOrig.setColor ( i + numColors, qRgb( 2 * qRed( rgb ) / 3, - 2 * qGreen( rgb ) / 3, 2 * qBlue( rgb ) / 3 ) ); + QRgb rgb = imgOrig.color( i ); + imgOrig.setColor ( i + numColors, qRgb( 2 * qRed( rgb ) / 3, + 2 * qGreen( rgb ) / 3, 2 * qBlue( rgb ) / 3 ) ); } // else go one with making the map... if ( bIllum ) { - // do a daylight mask - dayNight(&imgOrig); + // do a daylight mask + dayNight(&imgOrig); } // redo the width and height wImg = w; hImg = h; ox = ( wImg / 2 ) - int( wImg * 0.0275 ); oy = hImg / 2; pixCurr->convertFromImage( imgOrig.smoothScale(w, h), QPixmap::ThresholdDither ); } void ZoneMap::drawCity( QPainter *p, const ZoneField *pCity ) { int x, y; p->setPen( red ); zoneToWin( pCity->x(), pCity->y(), x, y ); p->drawRect( x - iCITYOFFSET, y - iCITYOFFSET, iCITYSIZE, iCITYSIZE ); } void ZoneMap::drawContents( QPainter *p, int cx, int cy, int cw, int ch ) { // if there is a need to resize, then do it... // get our drawable area drawableW = width() - 2 * frameWidth(); drawableH = height() - 2 * frameWidth(); int pixmapW = pixCurr->width(), pixmapH = pixCurr->height(); if ( !bZoom && ( ( pixmapW != drawableW ) || ( pixmapH != drawableH) ) ) { - makeMap( drawableW, drawableH ); + makeMap( drawableW, drawableH ); } // taken from the scrollview example... int rowheight = pixCurr->height(); int toprow = cy / rowheight; int bottomrow = ( cy + ch + rowheight - 1 ) / rowheight; int colwidth = pixCurr->width(); int leftcol= cx / colwidth; int rightcol= ( cx + cw + colwidth - 1 ) / colwidth; for ( int r = toprow; r <= bottomrow; r++ ) { - int py = r * rowheight; - for ( int c = leftcol; c <= rightcol; c++ ) { - int px = c * colwidth; - p->drawPixmap( px, py, *pixCurr ); - } + int py = r * rowheight; + for ( int c = leftcol; c <= rightcol; c++ ) { + int px = c * colwidth; + p->drawPixmap( px, py, *pixCurr ); + } } // Draw that city! if ( pLast ) - drawCity( p, pLast ); + drawCity( p, pLast ); } void ZoneMap::slotZoom( bool setZoom ) { bZoom = setZoom; if ( bZoom ) { - makeMap( 2 * wImg , 2 * hImg ); - resizeContents( wImg, hImg ); + makeMap( 2 * wImg , 2 * hImg ); + resizeContents( wImg, hImg ); } else { - makeMap( drawableW, drawableH ); - resizeContents( drawableW, drawableH ); + makeMap( drawableW, drawableH ); + resizeContents( drawableW, drawableH ); } } void ZoneMap::slotIllum( bool setIllum ) { bIllum = !setIllum; // make the map... makeMap( pixCurr->width(), pixCurr->height() ); updateContents( 0, 0, wImg, hImg ); } void ZoneMap::slotUpdate( void ) { // recalculate the light, most people will never see this, // but it is good to be complete makeMap ( pixCurr->width(), pixCurr->height() ); updateContents( contentsX(), contentsY(), drawableW, drawableH ); } void ZoneMap::slotRedraw( void ) { // paint over that pesky city... int x, y; if ( pRepaint ) { - pLast = 0; - zoneToWin(pRepaint->x(), pRepaint->y(), x, y); - updateContents( x - iCITYOFFSET, y - iCITYOFFSET, iCITYSIZE, iCITYSIZE); + pLast = 0; + zoneToWin(pRepaint->x(), pRepaint->y(), x, y); + updateContents( x - iCITYOFFSET, y - iCITYOFFSET, iCITYSIZE, iCITYSIZE); pRepaint = 0; } } void ZoneMap::changeClock( bool whichClock ) { ampm = whichClock; } diff --git a/core/settings/launcher/doctabsettings.cpp b/core/settings/launcher/doctabsettings.cpp index 179a7f9..dfdc9be 100644 --- a/core/settings/launcher/doctabsettings.cpp +++ b/core/settings/launcher/doctabsettings.cpp @@ -1,68 +1,72 @@ /* This file is part of the OPIE Project =. Copyright (c) 2002 Trolltech AS <info@trolltech.com> .=l. Copyright (c) 2003 Michael Lauer <mickeyl@handhelds.org> .>+-= _;:, .> :=|. This file is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This file is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General ..}^=.= = ; Public License for more details. ++= -. .` .: : = ...= . :.=- You should have received a copy of the GNU -. .:....=;==+<; General Public License along with this file; -_. . . )=. = see the file COPYING. If not, write to the -- :-=` Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "doctabsettings.h" +/* OPIE */ #include <qpe/config.h> +#include <opie2/odebug.h> +/* QT */ #include <qcheckbox.h> #include <qlayout.h> #include <qlabel.h> #include <qwhatsthis.h> + DocTabSettings::DocTabSettings( QWidget *parent, const char *name ):QWidget( parent, name ) { QBoxLayout *lay = new QVBoxLayout( this, 4, 4 ); _enable = new QCheckBox( tr( "Enable the Documents Tab" ), this ); Config cfg( "Launcher" ); cfg.setGroup( "DocTab" ); _enable->setChecked( cfg.readBoolEntry( "Enable", true ) ); lay->addWidget( _enable ); lay->addWidget( new QLabel( tr( "<b>Note:</b> Changing these settings may need restarting Opie to become effective." ), this ) ); lay->addStretch(); QWhatsThis::add( _enable, tr( "Check, if you want the Documents Tab to be visible." ) ); } void DocTabSettings::appletChanged() { } void DocTabSettings::accept() { - qDebug( "DocTabSettings::accept()" ); + odebug << "DocTabSettings::accept()" << oendl; Config cfg( "Launcher" ); cfg.setGroup( "DocTab" ); cfg.writeEntry( "Enable", _enable->isChecked() ); cfg.write(); } diff --git a/core/settings/launcher/inputmethodsettings.cpp b/core/settings/launcher/inputmethodsettings.cpp index e342c09..0422075 100644 --- a/core/settings/launcher/inputmethodsettings.cpp +++ b/core/settings/launcher/inputmethodsettings.cpp @@ -1,84 +1,88 @@ /* This file is part of the OPIE Project =. Copyright (c) 2002 Trolltech AS <info@trolltech.com> .=l. Copyright (c) 2003 Michael Lauer <mickeyl@handhelds.org> .>+-= _;:, .> :=|. This file is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This file is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General ..}^=.= = ; Public License for more details. ++= -. .` .: : = ...= . :.=- You should have received a copy of the GNU -. .:....=;==+<; General Public License along with this file; -_. . . )=. = see the file COPYING. If not, write to the -- :-=` Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "inputmethodsettings.h" +/* OPIE */ #include <qpe/config.h> +#include <opie2/odebug.h> +/* QT */ #include <qspinbox.h> #include <qcheckbox.h> #include <qlayout.h> #include <qlabel.h> #include <qwhatsthis.h> + InputMethodSettings::InputMethodSettings( QWidget *parent, const char *name ):QWidget( parent, name ) { QBoxLayout *lay = new QVBoxLayout( this, 4, 4 ); _resize = new QCheckBox( tr( "Resize application on Popup" ), this ); _float = new QCheckBox( tr( "Enable floating and resizing" ), this ); QHBoxLayout* hbox = new QHBoxLayout( lay, 4 ); hbox->addWidget( new QLabel( "Initial Width:", this ) ); _size = new QSpinBox( 10, 100, 10, this ); _size->setSuffix( "%" ); hbox->addWidget( _size ); hbox->addStretch(); Config cfg( "Launcher" ); cfg.setGroup( "InputMethods" ); _resize->setChecked( cfg.readBoolEntry( "Resize", true ) ); _float->setChecked( cfg.readBoolEntry( "Float", false ) ); _size->setValue( cfg.readNumEntry( "Width", 100 ) ); lay->addWidget( _resize ); lay->addWidget( _float ); lay->addWidget( new QLabel( tr( "<b>Note:</b> Changing these settings may need restarting Opie to become effective." ), this ) ); lay->addStretch(); QWhatsThis::add( _resize, tr( "Check, if you want the application to be automatically resized if the input method pops up." ) ); QWhatsThis::add( _float, tr( "Check, if you want to move and/or resize input methods" ) ); QWhatsThis::add( _size, tr( "Specify the percentage of the screen width for the input method" ) ); } void InputMethodSettings::appletChanged() { } void InputMethodSettings::accept() { - qDebug( "InputMethodSettings::accept()" ); + odebug << "InputMethodSettings::accept()" << oendl; Config cfg( "Launcher" ); cfg.setGroup( "InputMethods" ); cfg.writeEntry( "Resize", _resize->isChecked() ); cfg.writeEntry( "Float", _float->isChecked() ); cfg.writeEntry( "Width", _size->value() ); cfg.write(); } diff --git a/core/settings/launcher/tabdialog.cpp b/core/settings/launcher/tabdialog.cpp index 763b360..546e229 100644 --- a/core/settings/launcher/tabdialog.cpp +++ b/core/settings/launcher/tabdialog.cpp @@ -1,514 +1,516 @@ /* =. This file is part of the OPIE Project .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> .>+-= _;:, .> :=|. This file is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This file is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General ..}^=.= = ; Public License for more details. ++= -. .` .: : = ...= . :.=- You should have received a copy of the GNU -. .:....=;==+<; General Public License along with this file; -_. . . )=. = see the file COPYING. If not, write to the -- :-=` Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include "tabdialog.h" + +/* OPIE */ #include <qpe/resource.h> +#include <opie2/ofontselector.h> +#include <opie2/otabwidget.h> +#include <opie2/ocolorbutton.h> +#include <opie2/ofiledialog.h> +#include <opie2/odebug.h> +/* QT */ #include <qlayout.h> #include <qvbox.h> #include <qtabbar.h> #include <qiconview.h> #include <qapplication.h> #include <qlabel.h> #include <qradiobutton.h> #include <qbuttongroup.h> #include <qwhatsthis.h> #include <qcheckbox.h> -#include <opie2/ofontselector.h> -#include <opie2/otabwidget.h> -#include <opie2/ocolorbutton.h> -#include <opie2/ofiledialog.h> - -#include "tabdialog.h" - using namespace Opie::Ui; class SampleItem : public QIconViewItem { public: - SampleItem ( QIconView *v, const QString &text, const QPixmap &pix ) : QIconViewItem ( v, text ) - { - m_large = pix; - m_small. convertFromImage ( pix. convertToImage ( ). smoothScale ( pix. width ( ) / 2, pix. height ( ) / 2 )); - } - - void sizeChange ( ) - { - calcRect ( ); - repaint ( ); - } - - QPixmap *pixmap ( ) const - { - if ( iconView ( )-> itemTextPos ( ) == QIconView::Right ) - return (QPixmap *) &m_small; - else - return (QPixmap *) &m_large; - } + SampleItem ( QIconView *v, const QString &text, const QPixmap &pix ) : QIconViewItem ( v, text ) + { + m_large = pix; + m_small. convertFromImage ( pix. convertToImage ( ). smoothScale ( pix. width ( ) / 2, pix. height ( ) / 2 )); + } + + void sizeChange ( ) + { + calcRect ( ); + repaint ( ); + } + + QPixmap *pixmap ( ) const + { + if ( iconView ( )-> itemTextPos ( ) == QIconView::Right ) + return (QPixmap *) &m_small; + else + return (QPixmap *) &m_large; + } private: - QPixmap m_large, m_small; + QPixmap m_large, m_small; }; class SampleView : public QIconView { public: - SampleView ( QWidget *parent = 0, const char *name = 0 ) : QIconView ( parent, name ) - { - setItemsMovable ( false ); - setAutoArrange ( true ); - setSorting ( true ); - setFrameStyle ( QFrame::NoFrame ); - setSpacing ( 4 ); - setMargin ( 0 ); - setSelectionMode ( QIconView::NoSelection ); - setBackgroundMode ( PaletteBase ); - setViewMode ( TabConfig::Icon ); - calculateGrid ( Bottom ); - - - new SampleItem ( this, QObject::tr( "Sample 1" ), Resource::loadPixmap ( "datebook/DateBook" )); - new SampleItem ( this, QObject::tr( "Sample 2" ), Resource::loadPixmap ( "Calibrate" )); - new SampleItem ( this, QObject::tr( "Sample 3" ), Resource::loadPixmap ( "UnknownDocument" )); - - setBackgroundType ( TabConfig::Ruled, QString::null ); - - setMaximumHeight ( firstItem ( )-> height ( ) + 16 ); - } - - void setViewMode ( TabConfig::ViewMode m ) - { - viewport ( )-> setUpdatesEnabled ( false ); - - switch ( m ) { - case TabConfig::List: - setItemTextPos( QIconView::Right ); - break; - case TabConfig::Icon: - setItemTextPos( QIconView::Bottom ); - break; - } -// hideOrShowItems ( false ); - - for ( QIconViewItem *it = firstItem ( ); it; it = it-> nextItem ( )) - ((SampleItem *) it )-> sizeChange ( ); - arrangeItemsInGrid ( true ); - viewport ( )-> setUpdatesEnabled ( true ); - update ( ); - } - - - void setBackgroundType( TabConfig::BackgroundType t, const QString &val ) - { - switch ( t ) { - case TabConfig::Ruled: { - QPixmap bg ( width ( ), 9 ); - QPainter painter ( &bg ); - for ( int i = 0; i < 3; i++ ) { - painter. setPen ( white ); - painter. drawLine ( 0, i*3, width()-1, i*3 ); - painter. drawLine ( 0, i*3+1, width()-1, i*3+1 ); - painter. setPen ( colorGroup().background().light(105) ); - painter. drawLine ( 0, i*3+2, width()-1, i*3+2 ); - } - painter.end ( ); - setBackgroundPixmap ( bg ); - break; - } - - case TabConfig::SolidColor: { - setBackgroundPixmap ( QPixmap ( )); - if ( val. isEmpty ( )) - setBackgroundColor ( colorGroup ( ). base ( )); - else - setBackgroundColor ( val ); - break; - } - - case TabConfig::Image: { - qDebug( "Loading image: %s", val.latin1() ); - QPixmap bg ( Resource::loadPixmap ( "wallpaper/" + val )); - if ( bg. isNull ( )) { - QImageIO imgio; - imgio. setFileName ( val ); - QSize ds = qApp-> desktop ( )-> size ( ); - QString param ( "Scale( %1, %2, ScaleMin )" ); // No tr - imgio. setParameters ( param. arg ( ds. width ( )). arg ( ds. height ( )). latin1 ( )); - imgio. read ( ); - bg = imgio. image ( ); - } - setBackgroundPixmap ( bg ); - break; - } - } - m_bgtype = t; - viewport ( )-> update ( ); - } - - void setTextColor ( const QColor &tc ) - { - m_textcolor = tc; - QColorGroup cg = colorGroup ( ); - cg. setColor ( QColorGroup::Text, tc ); - setPalette ( QPalette ( cg, cg, cg )); - viewport ( )-> update ( ); - } - - void setViewFont ( const QFont &f ) - { - setFont ( f ); - } - - void setItemTextPos ( ItemTextPos pos ) - { - calculateGrid ( pos ); - QIconView::setItemTextPos( pos ); - } - - void calculateGrid ( ItemTextPos pos ) - { - int dw = QApplication::desktop ( )-> width ( ); - int viewerWidth = dw - style ( ).scrollBarExtent ( ). width ( ); - if ( pos == Bottom ) { - int cols = 3; - if ( viewerWidth <= 200 ) - cols = 2; - else if ( viewerWidth >= 400 ) - cols = viewerWidth/96; - setSpacing ( 4 ); - setGridX (( viewerWidth - ( cols + 1 ) * spacing ( )) / cols ); - setGridY ( fontMetrics ( ). height ( ) * 2 + 24 ); - } - else { - int cols = 2; - if ( viewerWidth < 150 ) - cols = 1; - else if ( viewerWidth >= 400 ) - cols = viewerWidth / 150; - setSpacing ( 2 ); - setGridX (( viewerWidth - ( cols + 1 ) * spacing ( )) / cols ); - setGridY ( fontMetrics ( ). height ( ) + 2 ); - } - } - - void paletteChange( const QPalette &p ) - { - static bool excllock = false; - - if ( excllock ) - return; - excllock = true; - - unsetPalette ( ); - QIconView::paletteChange ( p ); - if ( m_bgtype == TabConfig::Ruled ) - setBackgroundType ( TabConfig::Ruled, QString::null ); - QColorGroup cg = colorGroup ( ); - cg.setColor ( QColorGroup::Text, m_textcolor ); - setPalette ( QPalette ( cg, cg, cg )); - - excllock = false; - } - - void setBackgroundPixmap ( const QPixmap &pm ) - { - m_bgpix = pm; - } - - void setBackgroundColor ( const QColor &c ) - { - m_bgcolor = c; - } - - void drawBackground ( QPainter *p, const QRect &r ) - { - if ( !m_bgpix. isNull ( )) { - p-> drawTiledPixmap ( r, m_bgpix, QPoint (( r. x ( ) + contentsX ( )) % m_bgpix. width ( ), - ( r. y ( ) + contentsY ( )) % m_bgpix. height ( ))); - } - else - p-> fillRect ( r, m_bgcolor ); - } + SampleView ( QWidget *parent = 0, const char *name = 0 ) : QIconView ( parent, name ) + { + setItemsMovable ( false ); + setAutoArrange ( true ); + setSorting ( true ); + setFrameStyle ( QFrame::NoFrame ); + setSpacing ( 4 ); + setMargin ( 0 ); + setSelectionMode ( QIconView::NoSelection ); + setBackgroundMode ( PaletteBase ); + setViewMode ( TabConfig::Icon ); + calculateGrid ( Bottom ); + + + new SampleItem ( this, QObject::tr( "Sample 1" ), Resource::loadPixmap ( "datebook/DateBook" )); + new SampleItem ( this, QObject::tr( "Sample 2" ), Resource::loadPixmap ( "Calibrate" )); + new SampleItem ( this, QObject::tr( "Sample 3" ), Resource::loadPixmap ( "UnknownDocument" )); + + setBackgroundType ( TabConfig::Ruled, QString::null ); + + setMaximumHeight ( firstItem ( )-> height ( ) + 16 ); + } + + void setViewMode ( TabConfig::ViewMode m ) + { + viewport ( )-> setUpdatesEnabled ( false ); + + switch ( m ) { + case TabConfig::List: + setItemTextPos( QIconView::Right ); + break; + case TabConfig::Icon: + setItemTextPos( QIconView::Bottom ); + break; + } +// hideOrShowItems ( false ); + + for ( QIconViewItem *it = firstItem ( ); it; it = it-> nextItem ( )) + ((SampleItem *) it )-> sizeChange ( ); + arrangeItemsInGrid ( true ); + viewport ( )-> setUpdatesEnabled ( true ); + update ( ); + } + + + void setBackgroundType( TabConfig::BackgroundType t, const QString &val ) + { + switch ( t ) { + case TabConfig::Ruled: { + QPixmap bg ( width ( ), 9 ); + QPainter painter ( &bg ); + for ( int i = 0; i < 3; i++ ) { + painter. setPen ( white ); + painter. drawLine ( 0, i*3, width()-1, i*3 ); + painter. drawLine ( 0, i*3+1, width()-1, i*3+1 ); + painter. setPen ( colorGroup().background().light(105) ); + painter. drawLine ( 0, i*3+2, width()-1, i*3+2 ); + } + painter.end ( ); + setBackgroundPixmap ( bg ); + break; + } + + case TabConfig::SolidColor: { + setBackgroundPixmap ( QPixmap ( )); + if ( val. isEmpty ( )) + setBackgroundColor ( colorGroup ( ). base ( )); + else + setBackgroundColor ( val ); + break; + } + + case TabConfig::Image: { + odebug << "Loading image: " << val << "" << oendl; + QPixmap bg ( Resource::loadPixmap ( "wallpaper/" + val )); + if ( bg. isNull ( )) { + QImageIO imgio; + imgio. setFileName ( val ); + QSize ds = qApp-> desktop ( )-> size ( ); + QString param ( "Scale( %1, %2, ScaleMin )" ); // No tr + imgio. setParameters ( param. arg ( ds. width ( )). arg ( ds. height ( )). latin1 ( )); + imgio. read ( ); + bg = imgio. image ( ); + } + setBackgroundPixmap ( bg ); + break; + } + } + m_bgtype = t; + viewport ( )-> update ( ); + } + + void setTextColor ( const QColor &tc ) + { + m_textcolor = tc; + QColorGroup cg = colorGroup ( ); + cg. setColor ( QColorGroup::Text, tc ); + setPalette ( QPalette ( cg, cg, cg )); + viewport ( )-> update ( ); + } + + void setViewFont ( const QFont &f ) + { + setFont ( f ); + } + + void setItemTextPos ( ItemTextPos pos ) + { + calculateGrid ( pos ); + QIconView::setItemTextPos( pos ); + } + + void calculateGrid ( ItemTextPos pos ) + { + int dw = QApplication::desktop ( )-> width ( ); + int viewerWidth = dw - style ( ).scrollBarExtent ( ). width ( ); + if ( pos == Bottom ) { + int cols = 3; + if ( viewerWidth <= 200 ) + cols = 2; + else if ( viewerWidth >= 400 ) + cols = viewerWidth/96; + setSpacing ( 4 ); + setGridX (( viewerWidth - ( cols + 1 ) * spacing ( )) / cols ); + setGridY ( fontMetrics ( ). height ( ) * 2 + 24 ); + } + else { + int cols = 2; + if ( viewerWidth < 150 ) + cols = 1; + else if ( viewerWidth >= 400 ) + cols = viewerWidth / 150; + setSpacing ( 2 ); + setGridX (( viewerWidth - ( cols + 1 ) * spacing ( )) / cols ); + setGridY ( fontMetrics ( ). height ( ) + 2 ); + } + } + + void paletteChange( const QPalette &p ) + { + static bool excllock = false; + + if ( excllock ) + return; + excllock = true; + + unsetPalette ( ); + QIconView::paletteChange ( p ); + if ( m_bgtype == TabConfig::Ruled ) + setBackgroundType ( TabConfig::Ruled, QString::null ); + QColorGroup cg = colorGroup ( ); + cg.setColor ( QColorGroup::Text, m_textcolor ); + setPalette ( QPalette ( cg, cg, cg )); + + excllock = false; + } + + void setBackgroundPixmap ( const QPixmap &pm ) + { + m_bgpix = pm; + } + + void setBackgroundColor ( const QColor &c ) + { + m_bgcolor = c; + } + + void drawBackground ( QPainter *p, const QRect &r ) + { + if ( !m_bgpix. isNull ( )) { + p-> drawTiledPixmap ( r, m_bgpix, QPoint (( r. x ( ) + contentsX ( )) % m_bgpix. width ( ), + ( r. y ( ) + contentsY ( )) % m_bgpix. height ( ))); + } + else + p-> fillRect ( r, m_bgcolor ); + } private: - QColor m_textcolor; - QColor m_bgcolor; - QPixmap m_bgpix; - TabConfig::BackgroundType m_bgtype; + QColor m_textcolor; + QColor m_bgcolor; + QPixmap m_bgpix; + TabConfig::BackgroundType m_bgtype; }; TabDialog::TabDialog ( const QPixmap *tabicon, const QString &tabname, TabConfig &tc, QWidget *parent, const char *dname, bool modal, WFlags fl ) - : QDialog ( parent, dname, modal, fl | WStyle_ContextHelp ), m_tc ( tc ) + : QDialog ( parent, dname, modal, fl | WStyle_ContextHelp ), m_tc ( tc ) { - setCaption ( tr( "Edit Tab" )); + setCaption ( tr( "Edit Tab" )); - QVBoxLayout *lay = new QVBoxLayout ( this, 3, 3 ); + QVBoxLayout *lay = new QVBoxLayout ( this, 3, 3 ); - OTabWidget *tw = new OTabWidget ( this, "tabwidget", OTabWidget::Global, OTabWidget::Bottom ); - QWidget *bgtab; + OTabWidget *tw = new OTabWidget ( this, "tabwidget", OTabWidget::Global, OTabWidget::Bottom ); + QWidget *bgtab; - tw-> addTab ( bgtab = createBgTab ( tw ), "appearance/color", tr( "Background" )); - tw-> addTab ( createFontTab ( tw ), "font", tr( "Font" )); - tw-> addTab ( createIconTab ( tw ), "pixmap", tr( "Icons" ) ); + tw-> addTab ( bgtab = createBgTab ( tw ), "appearance/color", tr( "Background" )); + tw-> addTab ( createFontTab ( tw ), "font", tr( "Font" )); + tw-> addTab ( createIconTab ( tw ), "pixmap", tr( "Icons" ) ); - tw-> setCurrentTab ( bgtab ); + tw-> setCurrentTab ( bgtab ); - QWidget *sample = new QVBox ( this ); - QTabBar *tb = new QTabBar ( sample ); - QString name ( tr( "Previewing %1" ). arg ( tabname )); + QWidget *sample = new QVBox ( this ); + QTabBar *tb = new QTabBar ( sample ); + QString name ( tr( "Previewing %1" ). arg ( tabname )); - tb-> addTab ( tabicon ? new QTab ( *tabicon, name ) : new QTab ( name )); + tb-> addTab ( tabicon ? new QTab ( *tabicon, name ) : new QTab ( name )); - m_sample = new SampleView ( sample ); + m_sample = new SampleView ( sample ); - lay-> addWidget ( tw, 10 ); - lay-> addWidget ( sample, 1 ); + lay-> addWidget ( tw, 10 ); + lay-> addWidget ( sample, 1 ); - m_iconsize-> setButton ( tc. m_view ); - iconSizeClicked ( tc. m_view ); - //m_iconcolor-> setColor ( QColor ( m_tc. m_text_color )); - iconColorClicked ( m_iconcolor-> color ( )); - m_bgtype-> setButton ( tc. m_bg_type ); - //m_solidcolor-> setColor ( QColor ( tc. m_bg_color )); - m_bgimage = tc. m_bg_image; - bgTypeClicked ( tc. m_bg_type ); - m_fontuse-> setChecked ( tc. m_font_use ); - m_fontselect-> setSelectedFont ( QFont ( tc. m_font_family, tc. m_font_size, tc. m_font_weight, tc. m_font_italic )); - m_fontselect-> setEnabled ( m_fontuse-> isChecked ( )); - fontClicked ( m_fontselect-> selectedFont ( )); + m_iconsize-> setButton ( tc. m_view ); + iconSizeClicked ( tc. m_view ); + //m_iconcolor-> setColor ( QColor ( m_tc. m_text_color )); + iconColorClicked ( m_iconcolor-> color ( )); + m_bgtype-> setButton ( tc. m_bg_type ); + //m_solidcolor-> setColor ( QColor ( tc. m_bg_color )); + m_bgimage = tc. m_bg_image; + bgTypeClicked ( tc. m_bg_type ); + m_fontuse-> setChecked ( tc. m_font_use ); + m_fontselect-> setSelectedFont ( QFont ( tc. m_font_family, tc. m_font_size, tc. m_font_weight, tc. m_font_italic )); + m_fontselect-> setEnabled ( m_fontuse-> isChecked ( )); + fontClicked ( m_fontselect-> selectedFont ( )); - QWhatsThis::add ( sample, tr( "This is a rough preview of what the currently selected Tab will look like." )); + QWhatsThis::add ( sample, tr( "This is a rough preview of what the currently selected Tab will look like." )); } TabDialog::~TabDialog ( ) { } QWidget *TabDialog::createFontTab ( QWidget *parent ) { QWidget *tab = new QWidget ( parent, "FontTab" ); QVBoxLayout *vertLayout = new QVBoxLayout ( tab, 3, 3 ); - m_fontuse = new QCheckBox ( tr( "Use a custom font" ), tab ); - vertLayout-> addWidget ( m_fontuse ); + m_fontuse = new QCheckBox ( tr( "Use a custom font" ), tab ); + vertLayout-> addWidget ( m_fontuse ); m_fontselect = new OFontSelector ( false, tab, "fontsel" ); vertLayout-> addWidget ( m_fontselect ); - connect ( m_fontuse, SIGNAL( toggled(bool)), m_fontselect, SLOT( setEnabled(bool))); + connect ( m_fontuse, SIGNAL( toggled(bool)), m_fontselect, SLOT( setEnabled(bool))); connect( m_fontselect, SIGNAL( fontSelected(const QFont&)), this, SLOT( fontClicked(const QFont&))); return tab; } QWidget *TabDialog::createBgTab ( QWidget *parent ) { QWidget *tab = new QWidget( parent, "BgTab" ); QVBoxLayout *vertLayout = new QVBoxLayout( tab, 3, 3 ); QGridLayout* gridLayout = new QGridLayout ( vertLayout ); gridLayout-> setColStretch ( 1, 10 ); QLabel* label = new QLabel( tr( "Type:" ), tab ); gridLayout-> addWidget ( label, 0, 0 ); m_bgtype = new QButtonGroup( tab, "buttongroup" ); m_bgtype-> hide ( ); m_bgtype-> setExclusive ( true ); - QRadioButton *rb; + QRadioButton *rb; rb = new QRadioButton( tr( "Ruled" ), tab, "ruled" ); m_bgtype-> insert ( rb, TabConfig::Ruled ); gridLayout-> addWidget( rb, 0, 1 ); - QHBoxLayout *hb = new QHBoxLayout ( ); - hb-> setSpacing ( 3 ); + QHBoxLayout *hb = new QHBoxLayout ( ); + hb-> setSpacing ( 3 ); rb = new QRadioButton( tr( "Solid color" ), tab, "solid" ); m_bgtype-> insert ( rb, TabConfig::SolidColor ); hb-> addWidget ( rb ); - hb-> addSpacing ( 10 ); + hb-> addSpacing ( 10 ); - m_solidcolor = new Opie::OColorButton ( tab, QColor ( m_tc. m_bg_color ) ); - connect ( m_solidcolor, SIGNAL( colorSelected(const QColor&)), this, SLOT( bgColorClicked(const QColor&))); - hb-> addWidget ( m_solidcolor ); - hb-> addStretch ( 10 ); + m_solidcolor = new Opie::OColorButton ( tab, QColor ( m_tc. m_bg_color ) ); + connect ( m_solidcolor, SIGNAL( colorSelected(const QColor&)), this, SLOT( bgColorClicked(const QColor&))); + hb-> addWidget ( m_solidcolor ); + hb-> addStretch ( 10 ); gridLayout-> addLayout ( hb, 1, 1 ); - hb = new QHBoxLayout ( ); - hb-> setSpacing ( 3 ); + hb = new QHBoxLayout ( ); + hb-> setSpacing ( 3 ); - rb = new QRadioButton( tr( "Image" ), tab, "image" ); + rb = new QRadioButton( tr( "Image" ), tab, "image" ); m_bgtype-> insert ( rb, TabConfig::Image ); hb-> addWidget( rb ); hb-> addSpacing ( 10 ); - m_imagebrowse = new QPushButton ( tr( "Select..." ), tab ); - connect ( m_imagebrowse, SIGNAL( clicked()), this, SLOT( bgImageClicked())); - hb-> addWidget ( m_imagebrowse ); - hb-> addStretch ( 10 ); + m_imagebrowse = new QPushButton ( tr( "Select..." ), tab ); + connect ( m_imagebrowse, SIGNAL( clicked()), this, SLOT( bgImageClicked())); + hb-> addWidget ( m_imagebrowse ); + hb-> addStretch ( 10 ); gridLayout-> addLayout ( hb, 2, 1 ); - QPushButton *p = new QPushButton ( tr( "Default" ), tab ); - connect ( p, SIGNAL( clicked()), this, SLOT( bgDefaultClicked())); - gridLayout-> addWidget ( p, 3, 1 ); + QPushButton *p = new QPushButton ( tr( "Default" ), tab ); + connect ( p, SIGNAL( clicked()), this, SLOT( bgDefaultClicked())); + gridLayout-> addWidget ( p, 3, 1 ); - connect ( m_bgtype, SIGNAL( clicked(int)), this, SLOT( bgTypeClicked(int))); + connect ( m_bgtype, SIGNAL( clicked(int)), this, SLOT( bgTypeClicked(int))); - vertLayout-> addStretch ( 10 ); + vertLayout-> addStretch ( 10 ); - return tab; + return tab; } QWidget *TabDialog::createIconTab ( QWidget *parent ) { QWidget *tab = new QWidget( parent, "IconTab" ); QVBoxLayout *vertLayout = new QVBoxLayout( tab, 3, 3 ); QGridLayout* gridLayout = new QGridLayout ( vertLayout ); gridLayout-> setColStretch ( 1, 10 ); QLabel* label = new QLabel( tr( "Size:" ), tab ); gridLayout-> addWidget ( label, 0, 0 ); m_iconsize = new QButtonGroup( tab, "buttongroup" ); m_iconsize-> hide ( ); m_iconsize-> setExclusive ( true ); - QRadioButton *rb; + QRadioButton *rb; rb = new QRadioButton( tr( "Small" ), tab, "iconsmall" ); m_iconsize-> insert ( rb, TabConfig::List ); gridLayout-> addWidget( rb, 0, 1 ); rb = new QRadioButton( tr( "Large" ), tab, "iconlarge" ); m_iconsize-> insert ( rb, TabConfig::Icon ); gridLayout-> addWidget( rb, 1, 1 ); - connect ( m_iconsize, SIGNAL( clicked(int)), this, SLOT( iconSizeClicked(int))); + connect ( m_iconsize, SIGNAL( clicked(int)), this, SLOT( iconSizeClicked(int))); -// vertLayout-> addSpacing ( 8 ); +// vertLayout-> addSpacing ( 8 ); -// gridLayout = new QGridLayout ( vertLayout ); - gridLayout-> addRowSpacing ( 2, 8 ); +// gridLayout = new QGridLayout ( vertLayout ); + gridLayout-> addRowSpacing ( 2, 8 ); - label = new QLabel ( tr( "Color:" ), tab ); - gridLayout-> addWidget ( label, 3, 0 ); + label = new QLabel ( tr( "Color:" ), tab ); + gridLayout-> addWidget ( label, 3, 0 ); - m_iconcolor = new Opie::OColorButton ( tab, QColor ( m_tc. m_text_color ) ); - connect ( m_iconcolor, SIGNAL( colorSelected(const QColor&)), this, SLOT( iconColorClicked(const QColor&))); - gridLayout-> addWidget ( m_iconcolor, 3, 1, AlignLeft ); + m_iconcolor = new Opie::OColorButton ( tab, QColor ( m_tc. m_text_color ) ); + connect ( m_iconcolor, SIGNAL( colorSelected(const QColor&)), this, SLOT( iconColorClicked(const QColor&))); + gridLayout-> addWidget ( m_iconcolor, 3, 1, AlignLeft ); - vertLayout-> addStretch ( 10 ); + vertLayout-> addStretch ( 10 ); - return tab; + return tab; } void TabDialog::iconSizeClicked ( int s ) { - m_sample-> setViewMode ((TabConfig::ViewMode) s ); + m_sample-> setViewMode ((TabConfig::ViewMode) s ); } void TabDialog::fontClicked ( const QFont &f ) { - m_sample-> setViewFont ( f ); + m_sample-> setViewFont ( f ); } void TabDialog::bgTypeClicked ( int t ) { - QString s; + QString s; - if ( m_bgtype-> id ( m_bgtype-> selected ( )) != t ) - m_bgtype-> setButton ( t ); + if ( m_bgtype-> id ( m_bgtype-> selected ( )) != t ) + m_bgtype-> setButton ( t ); - m_solidcolor-> setEnabled ( t == TabConfig::SolidColor ); - m_imagebrowse-> setEnabled ( t == TabConfig::Image ); + m_solidcolor-> setEnabled ( t == TabConfig::SolidColor ); + m_imagebrowse-> setEnabled ( t == TabConfig::Image ); - if ( t == TabConfig::SolidColor ) - s = m_solidcolor-> color ( ). name ( ); - else if ( t == TabConfig::Image ) - s = Resource::findPixmap ( m_bgimage ); + if ( t == TabConfig::SolidColor ) + s = m_solidcolor-> color ( ). name ( ); + else if ( t == TabConfig::Image ) + s = Resource::findPixmap ( m_bgimage ); - m_sample-> setBackgroundType ((TabConfig::BackgroundType) t, s ); + m_sample-> setBackgroundType ((TabConfig::BackgroundType) t, s ); } void TabDialog::bgColorClicked ( const QColor & ) { - bgTypeClicked ( TabConfig::SolidColor ); + bgTypeClicked ( TabConfig::SolidColor ); } void TabDialog::iconColorClicked ( const QColor &col ) { - m_sample-> setTextColor ( col ); + m_sample-> setTextColor ( col ); } void TabDialog::bgImageClicked ( ) { - // ### use OFileSelector here ### - // this is just a quick c&p from the old appearance app - - MimeTypes types; - QStringList list; - list << "image/*"; - types. insert ( "Images", list ); - - QString file = OFileDialog::getOpenFileName ( 1, "/", QString::null, types ); - if ( !file. isEmpty ( )) { - m_bgimage = DocLnk ( file ). file ( ); - bgTypeClicked ( TabConfig::Image ); - } + // ### use OFileSelector here ### + // this is just a quick c&p from the old appearance app + + MimeTypes types; + QStringList list; + list << "image/*"; + types. insert ( "Images", list ); + + QString file = OFileDialog::getOpenFileName ( 1, "/", QString::null, types ); + if ( !file. isEmpty ( )) { + m_bgimage = DocLnk ( file ). file ( ); + bgTypeClicked ( TabConfig::Image ); + } } void TabDialog::bgDefaultClicked ( ) { - m_bgimage = "launcher/opie-background"; - bgTypeClicked ( TabConfig::Image ); + m_bgimage = "launcher/opie-background"; + bgTypeClicked ( TabConfig::Image ); } void TabDialog::accept ( ) { - m_tc. m_view = (TabConfig::ViewMode) m_iconsize-> id ( m_iconsize-> selected ( )); - m_tc. m_bg_type = (TabConfig::BackgroundType) m_bgtype-> id ( m_bgtype-> selected ( )); - m_tc. m_bg_color = m_solidcolor-> color ( ). name ( ); - m_tc. m_bg_image = m_bgimage; - m_tc. m_text_color = m_iconcolor-> color ( ). name ( ); + m_tc. m_view = (TabConfig::ViewMode) m_iconsize-> id ( m_iconsize-> selected ( )); + m_tc. m_bg_type = (TabConfig::BackgroundType) m_bgtype-> id ( m_bgtype-> selected ( )); + m_tc. m_bg_color = m_solidcolor-> color ( ). name ( ); + m_tc. m_bg_image = m_bgimage; + m_tc. m_text_color = m_iconcolor-> color ( ). name ( ); - m_tc. m_font_use = m_fontuse-> isChecked ( ); + m_tc. m_font_use = m_fontuse-> isChecked ( ); - if ( m_tc. m_font_use ) { - QFont f = m_fontselect-> selectedFont ( ); + if ( m_tc. m_font_use ) { + QFont f = m_fontselect-> selectedFont ( ); - m_tc. m_font_family = f. family ( ); - m_tc. m_font_size = f. pointSize ( ); - m_tc. m_font_weight = f. weight ( ); - m_tc. m_font_italic = f. italic ( ); - } + m_tc. m_font_family = f. family ( ); + m_tc. m_font_size = f. pointSize ( ); + m_tc. m_font_weight = f. weight ( ); + m_tc. m_font_italic = f. italic ( ); + } - QDialog::accept ( ); + QDialog::accept ( ); } diff --git a/core/settings/launcher/taskbarsettings.cpp b/core/settings/launcher/taskbarsettings.cpp index 43886c9..8dd9e97 100644 --- a/core/settings/launcher/taskbarsettings.cpp +++ b/core/settings/launcher/taskbarsettings.cpp @@ -1,172 +1,176 @@ /* This file is part of the OPIE Project =. Copyright (c) 2002 Trolltech AS <info@trolltech.com> .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> .>+-= _;:, .> :=|. This file is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This file is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General ..}^=.= = ; Public License for more details. -++= -. .` .: +++= -. .` .: : = ...= . :.=- You should have received a copy of the GNU -. .:....=;==+<; General Public License along with this file; -_. . . )=. = see the file COPYING. If not, write to the -- :-=` Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "taskbarsettings.h" +/* OPIE */ #include <qpe/config.h> #include <qpe/qlibrary.h> #include <qpe/qpeapplication.h> #include <qpe/taskbarappletinterface.h> #include <qpe/qcopenvelope_qws.h> +#include <opie2/odebug.h> +/* QT */ #include <qdir.h> #include <qlistview.h> #include <qheader.h> #include <qlayout.h> #include <qlabel.h> #include <qwhatsthis.h> +/* STD */ #include <stdlib.h> TaskbarSettings::TaskbarSettings ( QWidget *parent, const char *name ) - : QWidget ( parent, name ) + : QWidget ( parent, name ) { - m_applets_changed = false; + m_applets_changed = false; - QBoxLayout *lay = new QVBoxLayout ( this, 4, 4 ); + QBoxLayout *lay = new QVBoxLayout ( this, 4, 4 ); - QLabel *l = new QLabel ( tr( "Load applets in Taskbar:" ), this ); - lay-> addWidget ( l ); + QLabel *l = new QLabel ( tr( "Load applets in Taskbar:" ), this ); + lay-> addWidget ( l ); - m_list = new QListView ( this ); - m_list-> addColumn ( "foobar" ); - m_list-> header ( )-> hide ( ); + m_list = new QListView ( this ); + m_list-> addColumn ( "foobar" ); + m_list-> header ( )-> hide ( ); - lay-> addWidget ( m_list ); + lay-> addWidget ( m_list ); - QWhatsThis::add ( m_list, tr( "Check the applets that you want displayed in the Taskbar." )); + QWhatsThis::add ( m_list, tr( "Check the applets that you want displayed in the Taskbar." )); - connect ( m_list, SIGNAL( clicked(QListViewItem*)), this, SLOT( appletChanged())); + connect ( m_list, SIGNAL( clicked(QListViewItem*)), this, SLOT( appletChanged())); - init ( ); + init ( ); } void TaskbarSettings::init ( ) { - Config cfg ( "Taskbar" ); - cfg. setGroup ( "Applets" ); - QStringList exclude = cfg. readListEntry ( "ExcludeApplets", ',' ); + Config cfg ( "Taskbar" ); + cfg. setGroup ( "Applets" ); + QStringList exclude = cfg. readListEntry ( "ExcludeApplets", ',' ); - QString path = QPEApplication::qpeDir ( ) + "/plugins/applets"; + QString path = QPEApplication::qpeDir ( ) + "/plugins/applets"; #ifdef Q_OS_MACX - QStringList list = QDir ( path, "lib*.dylib" ). entryList ( ); + QStringList list = QDir ( path, "lib*.dylib" ). entryList ( ); #else - QStringList list = QDir ( path, "lib*.so" ). entryList ( ); + QStringList list = QDir ( path, "lib*.so" ). entryList ( ); #endif /* Q_OS_MACX */ - for ( QStringList::Iterator it = list. begin ( ); it != list. end ( ); ++it ) { - QString name; - QPixmap icon; - TaskbarNamedAppletInterface *iface = 0; - - qWarning("Load applet: %s", (*it).latin1() ); - QLibrary *lib = new QLibrary ( path + "/" + *it ); - lib-> queryInterface ( IID_TaskbarNamedApplet, (QUnknownInterface**) &iface ); - qWarning("<1>"); - if ( iface ) { - qWarning("<2>"); - QString lang = getenv( "LANG" ); - QTranslator *trans = new QTranslator ( qApp ); - QString type = (*it). left ((*it). find (".")); - QString tfn = QPEApplication::qpeDir ( ) + "/i18n/" + lang + "/" + type + ".qm"; - if ( trans-> load ( tfn )) - qApp-> installTranslator ( trans ); - else - delete trans; - name = iface-> name ( ); - icon = iface-> icon ( ); - iface-> release ( ); - } - qWarning("<3>"); - if ( !iface ) { - qWarning("<4>"); - lib-> queryInterface ( IID_TaskbarApplet, (QUnknownInterface**) &iface ); - - if ( iface ) { - qWarning("<5>"); - name = (*it). mid ( 3 ); - qWarning("Found applet: %s", name.latin1() ); + for ( QStringList::Iterator it = list. begin ( ); it != list. end ( ); ++it ) { + QString name; + QPixmap icon; + TaskbarNamedAppletInterface *iface = 0; + + owarn << "Load applet: " << (*it) << "" << oendl; + QLibrary *lib = new QLibrary ( path + "/" + *it ); + lib-> queryInterface ( IID_TaskbarNamedApplet, (QUnknownInterface**) &iface ); + owarn << "<1>" << oendl; + if ( iface ) { + owarn << "<2>" << oendl; + QString lang = getenv( "LANG" ); + QTranslator *trans = new QTranslator ( qApp ); + QString type = (*it). left ((*it). find (".")); + QString tfn = QPEApplication::qpeDir ( ) + "/i18n/" + lang + "/" + type + ".qm"; + if ( trans-> load ( tfn )) + qApp-> installTranslator ( trans ); + else + delete trans; + name = iface-> name ( ); + icon = iface-> icon ( ); + iface-> release ( ); + } + owarn << "<3>" << oendl; + if ( !iface ) { + owarn << "<4>" << oendl; + lib-> queryInterface ( IID_TaskbarApplet, (QUnknownInterface**) &iface ); + + if ( iface ) { + owarn << "<5>" << oendl; + name = (*it). mid ( 3 ); + owarn << "Found applet: " << name << "" << oendl; #ifdef Q_OS_MACX - int sep = name. find( ".dylib" ); + int sep = name. find( ".dylib" ); #else - int sep = name. find( ".so" ); + int sep = name. find( ".so" ); #endif /* Q_OS_MACX */ - if ( sep > 0 ) - name. truncate ( sep ); - sep = name. find ( "applet" ); - if ( sep == (int) name.length ( ) - 6 ) - name. truncate ( sep ); - name[0] = name[0]. upper ( ); - iface-> release ( ); - } - } - qWarning("<6>"); - - if ( iface ) { - qWarning("<7>"); - QCheckListItem *item; - item = new QCheckListItem ( m_list, name, QCheckListItem::CheckBox ); - if ( !icon. isNull ( )) - item-> setPixmap ( 0, icon ); - item-> setOn ( exclude. find ( *it ) == exclude. end ( )); - m_applets [*it] = item; - } - lib-> unload ( ); - delete lib; - } + if ( sep > 0 ) + name. truncate ( sep ); + sep = name. find ( "applet" ); + if ( sep == (int) name.length ( ) - 6 ) + name. truncate ( sep ); + name[0] = name[0]. upper ( ); + iface-> release ( ); + } + } + owarn << "<6>" << oendl; + + if ( iface ) { + owarn << "<7>" << oendl; + QCheckListItem *item; + item = new QCheckListItem ( m_list, name, QCheckListItem::CheckBox ); + if ( !icon. isNull ( )) + item-> setPixmap ( 0, icon ); + item-> setOn ( exclude. find ( *it ) == exclude. end ( )); + m_applets [*it] = item; + } + lib-> unload ( ); + delete lib; + } } void TaskbarSettings::appletChanged() { - m_applets_changed = true; + m_applets_changed = true; } void TaskbarSettings::accept ( ) { - Config cfg ( "Taskbar" ); - cfg. setGroup ( "Applets" ); - - if ( m_applets_changed ) { - QStringList exclude; - QMap <QString, QCheckListItem *>::Iterator it; - for ( it = m_applets. begin ( ); it != m_applets. end ( ); ++it ) { - if ( !(*it)-> isOn ( )) - exclude << it. key ( ); - } - cfg. writeEntry ( "ExcludeApplets", exclude, ',' ); - } - cfg. writeEntry ( "SafeMode", false ); - cfg. write ( ); - - if ( m_applets_changed ) { - QCopEnvelope e ( "QPE/TaskBar", "reloadApplets()" ); - m_applets_changed = false; - } + Config cfg ( "Taskbar" ); + cfg. setGroup ( "Applets" ); + + if ( m_applets_changed ) { + QStringList exclude; + QMap <QString, QCheckListItem *>::Iterator it; + for ( it = m_applets. begin ( ); it != m_applets. end ( ); ++it ) { + if ( !(*it)-> isOn ( )) + exclude << it. key ( ); + } + cfg. writeEntry ( "ExcludeApplets", exclude, ',' ); + } + cfg. writeEntry ( "SafeMode", false ); + cfg. write ( ); + + if ( m_applets_changed ) { + QCopEnvelope e ( "QPE/TaskBar", "reloadApplets()" ); + m_applets_changed = false; + } } diff --git a/core/settings/light-and-power/light.cpp b/core/settings/light-and-power/light.cpp index d64a063..424a64c 100644 --- a/core/settings/light-and-power/light.cpp +++ b/core/settings/light-and-power/light.cpp @@ -1,314 +1,317 @@ /* This file is part of the OPIE Project =. Copyright (c) 2002 Maximilian Reiss <harlekin@handhelds.org> .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org> .>+-= _;:, .> :=|. This file is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This file is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU General ..}^=.= = ; Public License for more details. ++= -. .` .: : = ...= . :.=- You should have received a copy of the GNU -. .:....=;==+<; General Public License along with this file; -_. . . )=. = see the file COPYING. If not, write to the -- :-=` Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "light.h" #include "sensor.h" +/* OPIE */ #include <opie2/odevice.h> +#include <opie2/odebug.h> #include <qpe/config.h> #include <qpe/power.h> #if defined(Q_WS_QWS) && !defined(QT_NO_COP) #include <qpe/qcopenvelope_qws.h> #endif +/* QT */ #include <qlabel.h> #include <qcheckbox.h> #include <qtabwidget.h> #include <qslider.h> #include <qspinbox.h> #include <qpushbutton.h> #include <qgroupbox.h> #include <qcombobox.h> using namespace Opie::Core; LightSettings::LightSettings( QWidget* parent, const char* name, WFlags ) - : LightSettingsBase( parent, name, false, WStyle_ContextHelp ) + : LightSettingsBase( parent, name, false, WStyle_ContextHelp ) { - m_bres = ODevice::inst ( )-> displayBrightnessResolution ( ); - m_cres = ODevice::inst ( )-> displayContrastResolution ( ); + m_bres = ODevice::inst ( )-> displayBrightnessResolution ( ); + m_cres = ODevice::inst ( )-> displayContrastResolution ( ); // check whether to show the light sensor stuff - if ( !ODevice::inst ( )-> hasLightSensor ( )) { - auto_brightness-> hide ( ); - CalibrateLightSensor-> hide ( ); - auto_brightness_ac-> hide ( ); - CalibrateLightSensor_ac-> hide ( ); - } + if ( !ODevice::inst ( )-> hasLightSensor ( )) { + auto_brightness-> hide ( ); + CalibrateLightSensor-> hide ( ); + auto_brightness_ac-> hide ( ); + CalibrateLightSensor_ac-> hide ( ); + } // check whether to show the contrast stuff - if (m_cres) { - GroupLight->setTitle(tr("Backlight && Contrast")); - GroupLight_ac->setTitle(GroupLight->title()); - } else { - contrast->hide(); - contrast_ac->hide(); - } + if (m_cres) { + GroupLight->setTitle(tr("Backlight && Contrast")); + GroupLight_ac->setTitle(GroupLight->title()); + } else { + contrast->hide(); + contrast_ac->hide(); + } // check whether to show the cpu frequency stuff - QStrList freq = ODevice::inst()->allowedCpuFrequencies(); - if ( freq.count() ) { - frequency->insertStrList( freq ); - frequency_ac->insertStrList( freq ); - } else { - frequencyLabel->hide(); - frequency->hide(); - frequencyLabel_ac->hide(); - frequency_ac->hide(); - } + QStrList freq = ODevice::inst()->allowedCpuFrequencies(); + if ( freq.count() ) { + frequency->insertStrList( freq ); + frequency_ac->insertStrList( freq ); + } else { + frequencyLabel->hide(); + frequency->hide(); + frequencyLabel_ac->hide(); + frequency_ac->hide(); + } // check whether to show the hinge action stuff if ( !ODevice::inst()->hasHingeSensor() ) { closeHingeLabel->hide(); closeHingeAction->hide(); closeHingeLabel_ac->hide(); closeHingeAction_ac->hide(); } - Config config ( "apm" ); - config. setGroup ( "Battery" ); + Config config ( "apm" ); + config. setGroup ( "Battery" ); - // battery spinboxes - interval_dim-> setValue ( config. readNumEntry ( "Dim", 20 )); - interval_lightoff-> setValue ( config. readNumEntry ( "LightOff", 30 )); - interval_suspend-> setValue ( config. readNumEntry ( "Suspend", 60 )); + // battery spinboxes + interval_dim-> setValue ( config. readNumEntry ( "Dim", 20 )); + interval_lightoff-> setValue ( config. readNumEntry ( "LightOff", 30 )); + interval_suspend-> setValue ( config. readNumEntry ( "Suspend", 60 )); - // battery check and slider - LcdOffOnly->setChecked ( config. readBoolEntry ( "LcdOffOnly", false )); + // battery check and slider + LcdOffOnly->setChecked ( config. readBoolEntry ( "LcdOffOnly", false )); - // CPU frequency - frequency->setCurrentItem( config.readNumEntry("Freq", 0) ); + // CPU frequency + frequency->setCurrentItem( config.readNumEntry("Freq", 0) ); - // hinge action - closeHingeAction->setCurrentItem( config.readNumEntry("CloseHingeAction", 0) ); + // hinge action + closeHingeAction->setCurrentItem( config.readNumEntry("CloseHingeAction", 0) ); int bright = config. readNumEntry ( "Brightness", 127 ); - int contr = m_oldcontrast = config. readNumEntry ( "Contrast", 127 ); - brightness-> setTickInterval ( QMAX( 16, 256 / m_bres )); - brightness-> setLineStep ( QMAX( 1, 256 / m_bres )); - brightness-> setPageStep ( QMAX( 1, 256 / m_bres )); - brightness-> setValue ( bright ); - - if (m_cres) { - contrast-> setTickInterval ( QMAX( 16, 256 / m_cres )); - contrast-> setLineStep ( QMAX( 1, 256 / m_cres )); - contrast-> setPageStep ( QMAX( 1, 256 / m_cres )); - contrast-> setValue ( contr ); - } - - // light sensor - auto_brightness-> setChecked ( config. readBoolEntry ( "LightSensor", false )); - m_sensordata = config. readListEntry ( "LightSensorData", ';' ); - - config. setGroup ( "AC" ); - - // ac spinboxes - interval_dim_ac-> setValue ( config. readNumEntry ( "Dim", 60 )); - interval_lightoff_ac-> setValue ( config. readNumEntry ( "LightOff", 120 )); - interval_suspend_ac-> setValue ( config. readNumEntry ( "Suspend", 0 )); - - // ac check and slider - LcdOffOnly_ac-> setChecked ( config. readBoolEntry ( "LcdOffOnly", false )); - - // CPU frequency - frequency_ac->setCurrentItem( config.readNumEntry("Freq", 0) ); - - // hinge action - closeHingeAction_ac->setCurrentItem( config.readNumEntry("CloseHingeAction", 0) ); - - bright = config. readNumEntry ( "Brightness", 255 ); - brightness_ac-> setTickInterval ( QMAX( 16, 256 / m_bres )); - brightness_ac-> setLineStep ( QMAX( 1, 256 / m_bres )); - brightness_ac-> setPageStep ( QMAX( 1, 256 / m_bres )); - brightness_ac-> setValue ( bright ); - - if (m_cres) { - contr = config. readNumEntry ( "Contrast", 127); - contrast_ac-> setTickInterval ( QMAX( 16, 256 / m_cres )); - contrast_ac-> setLineStep ( QMAX( 1, 256 / m_cres )); - contrast_ac-> setPageStep ( QMAX( 1, 256 / m_cres )); - contrast_ac-> setValue ( contr ); - } - - // light sensor - auto_brightness_ac-> setChecked ( config. readBoolEntry ( "LightSensor", false )); - m_sensordata_ac = config. readListEntry ( "LightSensorData", ';' ); - - // warnings - config. setGroup ( "Warnings" ); - warnintervalBox-> setValue ( config. readNumEntry ( "checkinterval", 10000 ) / 1000 ); - lowSpinBox-> setValue ( config. readNumEntry ( "powerverylow", 10 ) ); - criticalSpinBox-> setValue ( config. readNumEntry ( "powercritical", 5 ) ); - - m_resettimer = new QTimer ( this ); - connect ( m_resettimer, SIGNAL( timeout()), this, SLOT( resetBacklight())); - - if ( PowerStatusManager::readStatus ( ). acStatus ( ) != PowerStatus::Online ) { - tabs-> setCurrentPage ( 0 ); - } - else { - tabs-> setCurrentPage ( 1 ); - } - - connect ( brightness, SIGNAL( valueChanged(int)), this, SLOT( setBacklight(int))); - connect ( brightness_ac, SIGNAL( valueChanged(int)), this, SLOT( setBacklight(int))); - if (m_cres) { - connect ( contrast, SIGNAL( valueChanged(int)), this, SLOT( setContrast(int))); - connect ( contrast_ac, SIGNAL( valueChanged(int)), this, SLOT( setContrast(int))); - } - connect( frequency, SIGNAL( activated(int) ), this, SLOT( setFrequency(int) ) ); - connect( frequency_ac, SIGNAL( activated(int) ), this, SLOT( setFrequency(int) ) ); - connect( closeHingeAction, SIGNAL( activated(int) ), this, SLOT( setCloseHingeAction(int) ) ); - connect( closeHingeAction_ac, SIGNAL( activated(int) ), this, SLOT( setCloseHingeAction(int) ) ); + int contr = m_oldcontrast = config. readNumEntry ( "Contrast", 127 ); + brightness-> setTickInterval ( QMAX( 16, 256 / m_bres )); + brightness-> setLineStep ( QMAX( 1, 256 / m_bres )); + brightness-> setPageStep ( QMAX( 1, 256 / m_bres )); + brightness-> setValue ( bright ); + + if (m_cres) { + contrast-> setTickInterval ( QMAX( 16, 256 / m_cres )); + contrast-> setLineStep ( QMAX( 1, 256 / m_cres )); + contrast-> setPageStep ( QMAX( 1, 256 / m_cres )); + contrast-> setValue ( contr ); + } + + // light sensor + auto_brightness-> setChecked ( config. readBoolEntry ( "LightSensor", false )); + m_sensordata = config. readListEntry ( "LightSensorData", ';' ); + + config. setGroup ( "AC" ); + + // ac spinboxes + interval_dim_ac-> setValue ( config. readNumEntry ( "Dim", 60 )); + interval_lightoff_ac-> setValue ( config. readNumEntry ( "LightOff", 120 )); + interval_suspend_ac-> setValue ( config. readNumEntry ( "Suspend", 0 )); + + // ac check and slider + LcdOffOnly_ac-> setChecked ( config. readBoolEntry ( "LcdOffOnly", false )); + + // CPU frequency + frequency_ac->setCurrentItem( config.readNumEntry("Freq", 0) ); + + // hinge action + closeHingeAction_ac->setCurrentItem( config.readNumEntry("CloseHingeAction", 0) ); + + bright = config. readNumEntry ( "Brightness", 255 ); + brightness_ac-> setTickInterval ( QMAX( 16, 256 / m_bres )); + brightness_ac-> setLineStep ( QMAX( 1, 256 / m_bres )); + brightness_ac-> setPageStep ( QMAX( 1, 256 / m_bres )); + brightness_ac-> setValue ( bright ); + + if (m_cres) { + contr = config. readNumEntry ( "Contrast", 127); + contrast_ac-> setTickInterval ( QMAX( 16, 256 / m_cres )); + contrast_ac-> setLineStep ( QMAX( 1, 256 / m_cres )); + contrast_ac-> setPageStep ( QMAX( 1, 256 / m_cres )); + contrast_ac-> setValue ( contr ); + } + + // light sensor + auto_brightness_ac-> setChecked ( config. readBoolEntry ( "LightSensor", false )); + m_sensordata_ac = config. readListEntry ( "LightSensorData", ';' ); + + // warnings + config. setGroup ( "Warnings" ); + warnintervalBox-> setValue ( config. readNumEntry ( "checkinterval", 10000 ) / 1000 ); + lowSpinBox-> setValue ( config. readNumEntry ( "powerverylow", 10 ) ); + criticalSpinBox-> setValue ( config. readNumEntry ( "powercritical", 5 ) ); + + m_resettimer = new QTimer ( this ); + connect ( m_resettimer, SIGNAL( timeout()), this, SLOT( resetBacklight())); + + if ( PowerStatusManager::readStatus ( ). acStatus ( ) != PowerStatus::Online ) { + tabs-> setCurrentPage ( 0 ); + } + else { + tabs-> setCurrentPage ( 1 ); + } + + connect ( brightness, SIGNAL( valueChanged(int)), this, SLOT( setBacklight(int))); + connect ( brightness_ac, SIGNAL( valueChanged(int)), this, SLOT( setBacklight(int))); + if (m_cres) { + connect ( contrast, SIGNAL( valueChanged(int)), this, SLOT( setContrast(int))); + connect ( contrast_ac, SIGNAL( valueChanged(int)), this, SLOT( setContrast(int))); + } + connect( frequency, SIGNAL( activated(int) ), this, SLOT( setFrequency(int) ) ); + connect( frequency_ac, SIGNAL( activated(int) ), this, SLOT( setFrequency(int) ) ); + connect( closeHingeAction, SIGNAL( activated(int) ), this, SLOT( setCloseHingeAction(int) ) ); + connect( closeHingeAction_ac, SIGNAL( activated(int) ), this, SLOT( setCloseHingeAction(int) ) ); } LightSettings::~LightSettings ( ) { } void LightSettings::calibrateSensor ( ) { - Sensor *s = new Sensor ( m_sensordata, this ); - connect ( s, SIGNAL( viewBacklight(int)), this, SLOT( setBacklight(int))); - QPEApplication::execDialog( s ); - delete s; + Sensor *s = new Sensor ( m_sensordata, this ); + connect ( s, SIGNAL( viewBacklight(int)), this, SLOT( setBacklight(int))); + QPEApplication::execDialog( s ); + delete s; } void LightSettings::calibrateSensorAC ( ) { - Sensor *s = new Sensor ( m_sensordata_ac, this ); - connect ( s, SIGNAL( viewBacklight(int)), this, SLOT( setBacklight(int))); - QPEApplication::execDialog ( s ); - delete s; + Sensor *s = new Sensor ( m_sensordata_ac, this ); + connect ( s, SIGNAL( viewBacklight(int)), this, SLOT( setBacklight(int))); + QPEApplication::execDialog ( s ); + delete s; } void LightSettings::setBacklight ( int bright ) { - QCopEnvelope e ( "QPE/System", "setBacklight(int)" ); - e << bright; + QCopEnvelope e ( "QPE/System", "setBacklight(int)" ); + e << bright; - if ( bright != -1 ) { - m_resettimer-> stop ( ); - m_resettimer-> start ( 4000, true ); - } + if ( bright != -1 ) { + m_resettimer-> stop ( ); + m_resettimer-> start ( 4000, true ); + } } void LightSettings::setContrast ( int contr ) { - if (contr == -1) contr = m_oldcontrast; - ODevice::inst ( )-> setDisplayContrast(contr); + if (contr == -1) contr = m_oldcontrast; + ODevice::inst ( )-> setDisplayContrast(contr); } void LightSettings::setFrequency ( int index ) { - qWarning("LightSettings::setFrequency(%d)", index); - ODevice::inst ( )-> setCurrentCpuFrequency(index); + owarn << "LightSettings::setFrequency(" << index << ")" << oendl; + ODevice::inst ( )-> setCurrentCpuFrequency(index); } void LightSettings::resetBacklight ( ) { - setBacklight ( -1 ); - setContrast ( -1 ); + setBacklight ( -1 ); + setContrast ( -1 ); } void LightSettings::setCloseHingeAction ( int index ) { - qWarning("LightSettings::setCloseHingeStatus(%d)", index); + owarn << "LightSettings::setCloseHingeStatus(" << index << ")" << oendl; } void LightSettings::accept ( ) { - Config config ( "apm" ); - - // bat - config. setGroup ( "Battery" ); - config. writeEntry ( "LcdOffOnly", LcdOffOnly-> isChecked ( )); - config. writeEntry ( "Dim", interval_dim-> value ( )); - config. writeEntry ( "LightOff", interval_lightoff-> value ( )); - config. writeEntry ( "Suspend", interval_suspend-> value ( )); - config. writeEntry ( "Brightness", brightness-> value () ); - if (m_cres) - config. writeEntry ( "Contrast", contrast-> value () ); - config. writeEntry ( "Freq", frequency->currentItem() ); - config. writeEntry ( "CloseHingeAction", closeHingeAction->currentItem() ); - - // ac - config. setGroup ( "AC" ); - config. writeEntry ( "LcdOffOnly", LcdOffOnly_ac-> isChecked ( )); - config. writeEntry ( "Dim", interval_dim_ac-> value ( )); - config. writeEntry ( "LightOff", interval_lightoff_ac-> value ( )); - config. writeEntry ( "Suspend", interval_suspend_ac-> value ( )); - config. writeEntry ( "Brightness", brightness_ac-> value () ); - if (m_cres) - config. writeEntry ( "Contrast", contrast_ac-> value () ); - config. writeEntry ( "Freq", frequency_ac->currentItem() ); - config. writeEntry ( "CloseHingeAction", closeHingeAction_ac->currentItem() ); - - // only make light sensor stuff appear if the unit has a sensor - if ( ODevice::inst ( )-> hasLightSensor ( )) { - config. setGroup ( "Battery" ); - config. writeEntry ( "LightSensor", auto_brightness->isChecked() ); - config. writeEntry ( "LightSensorData", m_sensordata, ';' ); - config. setGroup ( "AC" ); - config. writeEntry ( "LightSensor", auto_brightness_ac->isChecked() ); - config. writeEntry ( "LightSensorData", m_sensordata_ac, ';' ); - } - - // advanced - config. setGroup ( "Warnings" ); - config. writeEntry ( "check_interval", warnintervalBox-> value ( ) * 1000 ); - config. writeEntry ( "power_verylow", lowSpinBox-> value ( )); - config. writeEntry ( "power_critical", criticalSpinBox-> value ( )); - config. write ( ); - - // notify the launcher - { - QCopEnvelope e ( "QPE/System", "reloadPowerWarnSettings()" ); - } - { - QCopEnvelope e ( "QPE/System", "setScreenSaverInterval(int)" ); - e << -1; - } - LightSettingsBase::accept ( ); + Config config ( "apm" ); + + // bat + config. setGroup ( "Battery" ); + config. writeEntry ( "LcdOffOnly", LcdOffOnly-> isChecked ( )); + config. writeEntry ( "Dim", interval_dim-> value ( )); + config. writeEntry ( "LightOff", interval_lightoff-> value ( )); + config. writeEntry ( "Suspend", interval_suspend-> value ( )); + config. writeEntry ( "Brightness", brightness-> value () ); + if (m_cres) + config. writeEntry ( "Contrast", contrast-> value () ); + config. writeEntry ( "Freq", frequency->currentItem() ); + config. writeEntry ( "CloseHingeAction", closeHingeAction->currentItem() ); + + // ac + config. setGroup ( "AC" ); + config. writeEntry ( "LcdOffOnly", LcdOffOnly_ac-> isChecked ( )); + config. writeEntry ( "Dim", interval_dim_ac-> value ( )); + config. writeEntry ( "LightOff", interval_lightoff_ac-> value ( )); + config. writeEntry ( "Suspend", interval_suspend_ac-> value ( )); + config. writeEntry ( "Brightness", brightness_ac-> value () ); + if (m_cres) + config. writeEntry ( "Contrast", contrast_ac-> value () ); + config. writeEntry ( "Freq", frequency_ac->currentItem() ); + config. writeEntry ( "CloseHingeAction", closeHingeAction_ac->currentItem() ); + + // only make light sensor stuff appear if the unit has a sensor + if ( ODevice::inst ( )-> hasLightSensor ( )) { + config. setGroup ( "Battery" ); + config. writeEntry ( "LightSensor", auto_brightness->isChecked() ); + config. writeEntry ( "LightSensorData", m_sensordata, ';' ); + config. setGroup ( "AC" ); + config. writeEntry ( "LightSensor", auto_brightness_ac->isChecked() ); + config. writeEntry ( "LightSensorData", m_sensordata_ac, ';' ); + } + + // advanced + config. setGroup ( "Warnings" ); + config. writeEntry ( "check_interval", warnintervalBox-> value ( ) * 1000 ); + config. writeEntry ( "power_verylow", lowSpinBox-> value ( )); + config. writeEntry ( "power_critical", criticalSpinBox-> value ( )); + config. write ( ); + + // notify the launcher + { + QCopEnvelope e ( "QPE/System", "reloadPowerWarnSettings()" ); + } + { + QCopEnvelope e ( "QPE/System", "setScreenSaverInterval(int)" ); + e << -1; + } + LightSettingsBase::accept ( ); } void LightSettings::done ( int r ) { - m_resettimer-> stop ( ); - resetBacklight ( ); + m_resettimer-> stop ( ); + resetBacklight ( ); - LightSettingsBase::done ( r ); - close ( ); + LightSettingsBase::done ( r ); + close ( ); } diff --git a/core/settings/security/security.cpp b/core/settings/security/security.cpp index 4eddb55..b917aea 100644 --- a/core/settings/security/security.cpp +++ b/core/settings/security/security.cpp @@ -1,396 +1,402 @@ /********************************************************************** ** Copyright (C) 2000 Trolltech AS. All rights reserved. ** ** This file is part of Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ #include "security.h" +/* OPIE */ #include <qpe/qpeapplication.h> #include <qpe/config.h> #include <qpe/password.h> #include <qpe/qpedialog.h> #include <qpe/qcopenvelope_qws.h> +#include <opie2/odebug.h> +/* QT */ #include <qcheckbox.h> #include <qpushbutton.h> #include <qcombobox.h> #include <qmessagebox.h> #include <qfile.h> #include <qtextstream.h> + +using namespace Opie::Core; + Security::Security( QWidget* parent, const char* name, WFlags fl ) : SecurityBase( parent, name, TRUE, WStyle_ContextHelp ) { valid=FALSE; Config cfg("Security"); cfg.setGroup("Passcode"); passcode = cfg.readEntry("passcode"); passcode_poweron->setChecked(cfg.readBoolEntry("passcode_poweron",FALSE)); cfg.setGroup("Sync"); int auth_peer = cfg.readNumEntry("auth_peer",0xc0a88100);//new default 192.168.129.0/24 int auth_peer_bits = cfg.readNumEntry("auth_peer_bits",24); selectNet(auth_peer,auth_peer_bits,TRUE); connect(syncnet, SIGNAL(textChanged(const QString&)), this, SLOT(setSyncNet(const QString&))); /* cfg.setGroup("Remote"); if ( telnetAvailable() ) telnet->setChecked(cfg.readEntry("allow_telnet")); else telnet->hide(); if ( sshAvailable() ) ssh->setChecked(cfg.readEntry("allow_ssh")); else ssh->hide(); */ QString configFile = QPEApplication::qpeDir() + "/etc/opie-login.conf"; Config loginCfg(configFile,Config::File); loginCfg.setGroup("General"); autoLoginName=loginCfg.readEntry("AutoLogin",""); if (autoLoginName.stripWhiteSpace().isEmpty()) { autoLogin=false; } else { autoLogin=true; } cfg.setGroup("SyncMode"); int mode = cfg.readNumEntry("Mode",2); // Default to Sharp switch( mode ) { case 0x01: syncModeCombo->setCurrentItem( 0 ); break; case 0x02: default: syncModeCombo->setCurrentItem( 1 ); break; case 0x04: syncModeCombo->setCurrentItem( 2 ); break; } connect(autologinToggle, SIGNAL(toggled(bool)), this, SLOT(toggleAutoLogin(bool))); connect(userlist, SIGNAL(activated(int)), this, SLOT(changeLoginName(int))); connect(changepasscode,SIGNAL(clicked()), this, SLOT(changePassCode())); connect(clearpasscode,SIGNAL(clicked()), this, SLOT(clearPassCode())); connect(restoredefaults,SIGNAL(clicked()), this, SLOT(restoreDefaults())); connect(deleteentry,SIGNAL(clicked()), this, SLOT(deleteListEntry())); loadUsers(); updateGUI(); dl = new QPEDialogListener(this); QPEApplication::showDialog( this ); } Security::~Security() { } void Security::deleteListEntry() { syncnet->removeItem(syncnet->currentItem()); } void Security::restoreDefaults() { QMessageBox unrecbox( tr("Attention"), - tr( "<p>All user-defined net ranges will be lost."), + tr( "<p>All user-defined net ranges will be lost."), QMessageBox::Warning, QMessageBox::Cancel, QMessageBox::Yes, QMessageBox::NoButton, 0, QString::null, TRUE, WStyle_StaysOnTop); unrecbox.setButtonText(QMessageBox::Cancel, tr("Cancel")); unrecbox.setButtonText(QMessageBox::Yes, tr("Ok")); if ( unrecbox.exec() == QMessageBox::Yes) { syncnet->clear(); insertDefaultRanges(); } syncModeCombo->setCurrentItem( 2 ); } void Security::insertDefaultRanges() { syncnet->insertItem( tr( "192.168.129.0/24" ) ); syncnet->insertItem( tr( "192.168.1.0/24" ) ); syncnet->insertItem( tr( "192.168.0.0/16" ) ); syncnet->insertItem( tr( "172.16.0.0/12" ) ); syncnet->insertItem( tr( "10.0.0.0/8" ) ); syncnet->insertItem( tr( "1.0.0.0/8" ) ); syncnet->insertItem( tr( "Any" ) ); syncnet->insertItem( tr( "None" ) ); } void Security::updateGUI() { bool empty = passcode.isEmpty(); changepasscode->setText( empty ? tr("Set passcode" ) : tr("Change passcode" ) ); passcode_poweron->setEnabled( !empty ); clearpasscode->setEnabled( !empty ); autologinToggle->setChecked(autoLogin); userlist->setEnabled(autoLogin); } void Security::show() { //valid=FALSE; setEnabled(FALSE); SecurityBase::show(); if ( passcode.isEmpty() ) { // could insist... //changePassCode(); //if ( passcode.isEmpty() ) //reject(); } else { - if (!valid) // security passcode was not asked yet, so ask now - { - QString pc = enterPassCode(tr("Enter passcode")); - if ( pc != passcode ) { - QMessageBox::critical(this, tr("Passcode incorrect"), - tr("The passcode entered is incorrect.\nAccess denied")); - reject(); - return; - } - } + if (!valid) // security passcode was not asked yet, so ask now + { + QString pc = enterPassCode(tr("Enter passcode")); + if ( pc != passcode ) { + QMessageBox::critical(this, tr("Passcode incorrect"), + tr("The passcode entered is incorrect.\nAccess denied")); + reject(); + return; + } + } } setEnabled(TRUE); valid=TRUE; } void Security::accept() { applySecurity(); QDialog::accept(); QCopEnvelope env("QPE/System", "securityChanged()" ); } void Security::done(int r) { QDialog::done(r); close(); } void Security::selectNet(int auth_peer,int auth_peer_bits, bool update) { QString sn; if ( auth_peer_bits == 0 && auth_peer == 0 ) { sn = tr("Any"); } else if ( auth_peer_bits == 32 && auth_peer == 0 ) { sn = tr("None"); } else { sn = QString::number((auth_peer>>24)&0xff) + "." + QString::number((auth_peer>>16)&0xff) + "." + QString::number((auth_peer>>8)&0xff) + "." + QString::number((auth_peer>>0)&0xff) + "/" + QString::number(auth_peer_bits); } //insert user-defined list of netranges upon start if (update) { - //User selected/active netrange first - syncnet->insertItem( tr( sn ) ); + //User selected/active netrange first + syncnet->insertItem( tr( sn ) ); - Config cfg("Security"); - cfg.setGroup("Sync"); + Config cfg("Security"); + cfg.setGroup("Sync"); - //set up defaults if needed, if someone manually deletes net0 he'll get a suprise hehe - QString test = cfg.readEntry("net0",""); - if (test.isEmpty()) { + //set up defaults if needed, if someone manually deletes net0 he'll get a suprise hehe + QString test = cfg.readEntry("net0",""); + if (test.isEmpty()) { insertDefaultRanges(); - } else { + } else { // 10 ought to be enough for everybody... :) // If you need more, don't forget to edit applySecurity() as well bool already_there=FALSE; for (int i=0; i<10; i++) { QString target, netrange; target.sprintf("net%d", i); netrange = cfg.readEntry(target,""); if (! netrange.isEmpty()){ //make sure we have no "twin" entries for (int i=0; i<syncnet->count(); i++) { if ( syncnet->text(i) == netrange ) { already_there=TRUE; } } if (! already_there) { syncnet->insertItem( tr( netrange ) ); } else { already_there=FALSE; } } } } } for (int i=0; i<syncnet->count(); i++) { if ( syncnet->text(i).left(sn.length()) == sn ) { syncnet->setCurrentItem(i); return; } } - qDebug("No match for \"%s\"",sn.latin1()); + odebug << "No match for \"" << sn << "\"" << oendl; } void Security::parseNet(const QString& sn,int& auth_peer,int& auth_peer_bits) { auth_peer=0; if ( sn == tr("Any") ) { auth_peer = 0; auth_peer_bits = 0; } else if ( sn == tr("None") ) { auth_peer = 0; auth_peer_bits = 32; } else { int x=0; for (int i=0; i<4; i++) { int nx = sn.find(QChar(i==3 ? '/' : '.'),x); auth_peer = (auth_peer<<8)|sn.mid(x,nx-x).toInt(); x = nx+1; } uint n = (uint)sn.find(' ',x)-x; auth_peer_bits = sn.mid(x,n).toInt(); } } void Security::loadUsers ( void ) { QFile passwd("/etc/passwd"); if ( passwd.open(IO_ReadOnly) ) { QTextStream t( &passwd ); QString s; QStringList account; while ( !t.eof() ) { account = QStringList::split(':',t.readLine()); // Hide disabled accounts if (*account.at(1)!="*") { userlist->insertItem(*account.at(0)); // Highlight this item if it is set to autologinToggle if ( *account.at(0) == autoLoginName) userlist->setCurrentItem(userlist->count()-1); } } passwd.close(); } } void Security::toggleAutoLogin(bool val) { autoLogin=val; userlist->setEnabled(val); if (!autoLogin) autoLoginName=userlist->currentText(); } void Security::setSyncNet(const QString& sn) { int auth_peer,auth_peer_bits; parseNet(sn,auth_peer,auth_peer_bits); selectNet(auth_peer,auth_peer_bits,FALSE); } void Security::applySecurity() { if ( valid ) { Config cfg("Security"); cfg.setGroup("Passcode"); cfg.writeEntry("passcode",passcode); cfg.writeEntry("passcode_poweron",passcode_poweron->isChecked()); cfg.setGroup("Sync"); int auth_peer=0; int auth_peer_bits; QString sn = syncnet->currentText(); parseNet(sn,auth_peer,auth_peer_bits); //this is the *selected* (active) net range cfg.writeEntry("auth_peer",auth_peer); cfg.writeEntry("auth_peer_bits",auth_peer_bits); - //write back all other net ranges in *cleartext* - for (int i=0; i<10; i++) { - QString target; - target.sprintf("net%d", i); - cfg.writeEntry(target,syncnet->text(i)); - } + //write back all other net ranges in *cleartext* + for (int i=0; i<10; i++) { + QString target; + target.sprintf("net%d", i); + cfg.writeEntry(target,syncnet->text(i)); + } #ifdef ODP #error "Use 0,1,2 and use Launcher" #endif /* keep the old code so we don't use currentItem directly */ int value = 0x02; switch( syncModeCombo->currentItem() ) { case 0: value = 0x01; break; case 1: value = 0x02; break; case 2: value = 0x04; break; } cfg.setGroup("SyncMode"); cfg.writeEntry( "Mode", value ); /* cfg.setGroup("Remote"); if ( telnetAvailable() ) cfg.writeEntry("allow_telnet",telnet->isChecked()); if ( sshAvailable() ) cfg.writeEntry("allow_ssh",ssh->isChecked()); // ### write ssh/telnet sys config files */ QString configFile = QPEApplication::qpeDir() + "/etc/opie-login.conf"; Config loginCfg(configFile,Config::File); loginCfg.setGroup("General"); if (autoLogin) { loginCfg.writeEntry("AutoLogin",autoLoginName); } else { loginCfg.removeEntry("AutoLogin"); } } } void Security::changeLoginName( int idx ) { autoLoginName = userlist->text(idx);; diff --git a/core/settings/security/security.pro b/core/settings/security/security.pro index 4a29ee2..4c1e68b 100644 --- a/core/settings/security/security.pro +++ b/core/settings/security/security.pro @@ -1,10 +1,10 @@ -CONFIG += qt warn_on quick-app -HEADERS = security.h -SOURCES = security.cpp main.cpp -INTERFACES = securitybase.ui +CONFIG += qt warn_on quick-app +HEADERS = security.h +SOURCES = security.cpp main.cpp +INTERFACES = securitybase.ui INCLUDEPATH += $(OPIEDIR)/include -DEPENDPATH += ../$(OPIEDIR)/include -LIBS += -lqpe -TARGET = security +DEPENDPATH += ../$(OPIEDIR)/include +LIBS += -lqpe -lopiecore2 +TARGET = security include ( $(OPIEDIR)/include.pro ) diff --git a/core/symlinker/main.cpp b/core/symlinker/main.cpp index 6a04980..96e7f3c 100644 --- a/core/symlinker/main.cpp +++ b/core/symlinker/main.cpp @@ -1,179 +1,185 @@ + +/* OPIE */ +#include <opie2/odebug.h> + +/* QT */ #include <qapplication.h> #include <qfile.h> #include <qfileinfo.h> #include <qdir.h> #include <qtextstream.h> #include <qstringlist.h> +/* STD */ #include <stdlib.h> -#include <unistd.h> //symlink() +#include <unistd.h> //symlink() #include <sys/stat.h> // mkdir() #include <sys/vfs.h> #include <mntent.h> #include <errno.h> static const char *listDir = "/usr/lib/ipkg/externinfo/"; static void createSymlinks( const QString &location, const QString &package ) { QFile inFile( location + "/usr/lib/ipkg/info/" + package + ".list" ); mkdir( "/usr/lib/ipkg", 0777 ); mkdir( listDir, 0777 ); QFile outFile( listDir + package + ".list"); -// qDebug( "createSymlinks %s -> %s", inFile.name().ascii(), outFile.name().ascii() ); - - - - if ( inFile.open(IO_ReadOnly) && outFile.open(IO_WriteOnly)) { - QTextStream in(&inFile); - QTextStream out(&outFile); - - QString s; - while ( !in.eof() ) { // until end of file... - s = in.readLine(); // line of text excluding '\n' -// qDebug( "Read: %s", s.ascii() ); - if (s.find(location,0,true) >= 0){ -// qDebug( "Found!" ); - s = s.replace(location,""); - } -// qDebug( "Read after: %s", s.ascii() ); - - // for s, do link/mkdir. - if ( s.right(1) == "/" ) { -// qDebug("do mkdir for %s", s.ascii()); - mkdir( s.ascii(), 0777 ); - //possible optimization: symlink directories - //that don't exist already. -- Risky. - } else { -// qDebug("do symlink for %s", s.ascii()); - QFileInfo ffi( s ); - //Don't try to symlink if a regular file exists already - if ( !ffi.exists() || ffi.isSymLink() ) { - if (symlink( (location+s).ascii(), s.ascii() ) != 0){ - if (errno == ENOENT){ -// perror("Symlink Failed! "); - QString e=s.ascii(); - e = e.replace(ffi.fileName(),""); -// qDebug("DirName : %s",e.ascii() ); - system ( QString("mkdir -p ")+e.ascii() ); - if (symlink( (location+s).ascii(), s.ascii() ) != 0) - qDebug ("Big problem creating symlink and directory"); - } - } -// qDebug ( "Created %s" ,s.ascii() ); - out << s << "\n"; - } else { - qDebug( "%s exists already, not symlinked", s.ascii() ); - } - } - } - inFile.close(); - outFile.close(); +// odebug << "createSymlinks " << inFile.name().ascii() << " -> " << outFile.name().ascii() << "" << oendl; + + + + if ( inFile.open(IO_ReadOnly) && outFile.open(IO_WriteOnly)) { + QTextStream in(&inFile); + QTextStream out(&outFile); + + QString s; + while ( !in.eof() ) { // until end of file... + s = in.readLine(); // line of text excluding '\n' +// odebug << "Read: " << s.ascii() << "" << oendl; + if (s.find(location,0,true) >= 0){ +// odebug << "Found!" << oendl; + s = s.replace(location,""); + } +// odebug << "Read after: " << s.ascii() << "" << oendl; + + // for s, do link/mkdir. + if ( s.right(1) == "/" ) { +// odebug << "do mkdir for " << s.ascii() << "" << oendl; + mkdir( s.ascii(), 0777 ); + //possible optimization: symlink directories + //that don't exist already. -- Risky. + } else { +// odebug << "do symlink for " << s.ascii() << "" << oendl; + QFileInfo ffi( s ); + //Don't try to symlink if a regular file exists already + if ( !ffi.exists() || ffi.isSymLink() ) { + if (symlink( (location+s).ascii(), s.ascii() ) != 0){ + if (errno == ENOENT){ +// perror("Symlink Failed! "); + QString e=s.ascii(); + e = e.replace(ffi.fileName(),""); +// odebug << "DirName : " << e.ascii() << "" << oendl; + system ( QString("mkdir -p ")+e.ascii() ); + if (symlink( (location+s).ascii(), s.ascii() ) != 0) + odebug << "Big problem creating symlink and directory" << oendl; + } + } +// qDebug ( "Created %s" ,s.ascii() ); + out << s << "\n"; + } else { + odebug << "" << s.ascii() << " exists already, not symlinked" << oendl; + } + } + } + inFile.close(); + outFile.close(); } } static void removeSymlinks( const QString &package ) { QFile inFile( listDir + package + ".list" ); - if ( inFile.open(IO_ReadOnly) ) { - QTextStream in(&inFile); - - QString s; - while ( !in.eof() ) { // until end of file... - s = in.readLine(); // line of text excluding '\n' -// qDebug("remove symlink %s", s.ascii()); - QFileInfo ffi( s ); - //Confirm that it's still a symlink. - if ( ffi.isSymLink() ){ - unlink( s.ascii() ); -// qDebug ( "Removed %s", s.ascii() );} -// else -// qDebug( "Not removed %s", s.ascii() ); - } - } - inFile.close(); - inFile.remove(); + if ( inFile.open(IO_ReadOnly) ) { + QTextStream in(&inFile); + + QString s; + while ( !in.eof() ) { // until end of file... + s = in.readLine(); // line of text excluding '\n' +// odebug << "remove symlink " << s.ascii() << "" << oendl; + QFileInfo ffi( s ); + //Confirm that it's still a symlink. + if ( ffi.isSymLink() ){ + unlink( s.ascii() ); +// qDebug ( "Removed %s", s.ascii() );} +// else +// odebug << "Not removed " << s.ascii() << "" << oendl; + } + } + inFile.close(); + inFile.remove(); } } /* Slightly hacky: we can't use StorageInfo, since we don't have a QApplication. We look for filesystems that have the directory /usr/lib/ipkg/info, and assume that they are removable media - with packages installed. This is safe even if eg. /usr is on a + with packages installed. This is safe even if eg. /usr is on a separate filesystem, since then we would be testing for /usr/usr/lib/ipkg/info, which should not exist. (And if it does they deserve to have it treated as removable.) */ static void updateSymlinks() { QDir lists( listDir ); QStringList knownPackages = lists.entryList( "*.list" ); // No tr - + struct mntent *me; FILE *mntfp = setmntent( "/etc/mtab", "r" ); if ( mntfp ) { - while ( (me = getmntent( mntfp )) != 0 ) { - QString root = me->mnt_dir; - if ( root == "/" ) - continue; - - QString info = root + "/usr/lib/ipkg/info"; - QDir infoDir( info ); -// qDebug( "looking at %s", info.ascii() ); - if ( infoDir.isReadable() ) { - const QFileInfoList *packages = infoDir.entryInfoList( "*.list" ); // No tr - QFileInfoListIterator it( *packages ); - QFileInfo *fi; - while (( fi = *it )) { - ++it; - if ( knownPackages.contains( fi->fileName() ) ) { -// qDebug( "found %s and we've seen it before", fi->fileName().latin1() ); - knownPackages.remove( fi->fileName() ); - } else { - //it's a new one - createSymlinks( root, fi->baseName() ); - } - - } - - } - } - endmntent( mntfp ); + while ( (me = getmntent( mntfp )) != 0 ) { + QString root = me->mnt_dir; + if ( root == "/" ) + continue; + + QString info = root + "/usr/lib/ipkg/info"; + QDir infoDir( info ); +// odebug << "looking at " << info.ascii() << "" << oendl; + if ( infoDir.isReadable() ) { + const QFileInfoList *packages = infoDir.entryInfoList( "*.list" ); // No tr + QFileInfoListIterator it( *packages ); + QFileInfo *fi; + while (( fi = *it )) { + ++it; + if ( knownPackages.contains( fi->fileName() ) ) { +// odebug << "found " << fi->fileName() << " and we've seen it before" << oendl; + knownPackages.remove( fi->fileName() ); + } else { + //it's a new one + createSymlinks( root, fi->baseName() ); + } + + } + + } + } + endmntent( mntfp ); } - - for ( QStringList::Iterator it = knownPackages.begin(); - it != knownPackages.end(); ++it ) { - // strip ".info" off the end. - removeSymlinks( (*it).left((*it).length()-5) ); + + for ( QStringList::Iterator it = knownPackages.begin(); + it != knownPackages.end(); ++it ) { + // strip ".info" off the end. + removeSymlinks( (*it).left((*it).length()-5) ); } } int main( int argc, char *argv[] ) { QApplication a( argc, argv, QApplication::Tty ); QString command = argc > 1 ? argv[1] : "update"; // No tr - + if ( command == "update" ) // No tr - updateSymlinks(); + updateSymlinks(); else if ( command == "create" && argc > 3 ) // No tr - createSymlinks( argv[2], argv[3] ); + createSymlinks( argv[2], argv[3] ); else if ( command == "remove" && argc > 2 ) // No tr - removeSymlinks( argv[2] ); + removeSymlinks( argv[2] ); else - qWarning( "Argument error" ); + owarn << "Argument error" << oendl; } diff --git a/core/symlinker/symlinker.pro b/core/symlinker/symlinker.pro index f850d46..50ad785 100644 --- a/core/symlinker/symlinker.pro +++ b/core/symlinker/symlinker.pro @@ -1,15 +1,15 @@ -TEMPLATE = app -CONFIG += qt warn_on -DESTDIR = $(OPIEDIR)/bin +TEMPLATE = app +CONFIG += qt warn_on +DESTDIR = $(OPIEDIR)/bin -HEADERS = -SOURCES = main.cpp -INTERFACES = +HEADERS = +SOURCES = main.cpp +INTERFACES = -TARGET = opie-update-symlinks -INCLUDEPATH += $(OPIEDIR)/include +TARGET = opie-update-symlinks +INCLUDEPATH += $(OPIEDIR)/include DEPENDPATH += $(OPIEDIR)/include . -LIBS += -lqpe +LIBS += -lqpe -lopiecore2 include ( $(OPIEDIR)/include.pro ) diff --git a/core/tools/quicklauncher/main.cpp b/core/tools/quicklauncher/main.cpp index d467d6e..c2467fb 100644 --- a/core/tools/quicklauncher/main.cpp +++ b/core/tools/quicklauncher/main.cpp @@ -1,268 +1,275 @@ /********************************************************************** ** Copyright (C) 2000-2003 Trolltech AS. All rights reserved. ** ** This file is part of the Qtopia Environment. ** ** This file may be distributed and/or modified under the terms of the ** GNU General Public License version 2 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ** ** See http://www.trolltech.com/gpl/ for GPL licensing information. ** ** Contact info@trolltech.com if any conditions of this licensing are ** not clear to you. ** **********************************************************************/ +#include "dropins.h" + +/* OPIE */ +#include <opie2/odebug.h> + +/* QT */ #include <qpainter.h> #include <qstrlist.h> #include <qtimer.h> #include <qguardedptr.h> #include <qcopchannel_qws.h> #define QTOPIA_INTERNAL_INITAPP #ifdef private # undef private #endif #define private public #include <qtopia/qpeapplication.h> #undef private + +/* STD */ #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> -#include "dropins.h" using QuickPrivate::PluginLoader; static QPEApplication *app = 0; static PluginLoader *loader = 0; static ApplicationInterface *appIface = 0; static QGuardedPtr<QWidget> mainWindow; #ifdef _OS_LINUX_ static char **argv0 = 0; static int argv_lth; extern char **environ; #ifndef SPT_BUFSIZE #define SPT_BUFSIZE 2048 #endif #include <stdarg.h> using namespace Opie::Ui; void setproctitle (const char *fmt,...) { int i; char buf[SPT_BUFSIZE]; va_list ap; if (!argv0) - return; + return; va_start(ap, fmt); (void) vsnprintf(buf, SPT_BUFSIZE, fmt, ap); va_end(ap); i = strlen (buf); if (i > argv_lth - 2) { - i = argv_lth - 2; - buf[i] = '\0'; + i = argv_lth - 2; + buf[i] = '\0'; } memset(argv0[0], '\0', argv_lth); /* clear the memory area */ (void) strcpy (argv0[0], buf); argv0[1] = NULL; } #endif class QuickLauncher : public QObject { Q_OBJECT public: QuickLauncher() : QObject() { - QCString ch("QPE/QuickLauncher-"); - ch += QString::number(getpid()); - qlChannel = new QCopChannel( ch, this); - connect( qlChannel, SIGNAL(received(const QCString&,const QByteArray&)), - this, SLOT(message(const QCString&,const QByteArray&)) ); + QCString ch("QPE/QuickLauncher-"); + ch += QString::number(getpid()); + qlChannel = new QCopChannel( ch, this); + connect( qlChannel, SIGNAL(received(const QCString&,const QByteArray&)), + this, SLOT(message(const QCString&,const QByteArray&)) ); } static void exec( int /*argc*/, char **argv ) { - QString appName = argv[0]; - int sep = appName.findRev( '/' ); - if ( sep > 0 ) - appName = appName.mid( sep+1 ); - - appIface = 0; - if ( loader->queryInterface(appName, IID_QtopiaApplication, (QUnknownInterface**)&appIface) == QS_OK ) { - mainWindow = appIface->createMainWindow( appName ); - } - if ( mainWindow ) { - if ( mainWindow->metaObject()->slotNames().contains("setDocument(const QString&)") ) { - app->showMainDocumentWidget( mainWindow ); - } else { - app->showMainWidget( mainWindow ); - } - } else { - qWarning( "Could not create application main window" ); - exit(-1); - } + QString appName = argv[0]; + int sep = appName.findRev( '/' ); + if ( sep > 0 ) + appName = appName.mid( sep+1 ); + + appIface = 0; + if ( loader->queryInterface(appName, IID_QtopiaApplication, (QUnknownInterface**)&appIface) == QS_OK ) { + mainWindow = appIface->createMainWindow( appName ); + } + if ( mainWindow ) { + if ( mainWindow->metaObject()->slotNames().contains("setDocument(const QString&)") ) { + app->showMainDocumentWidget( mainWindow ); + } else { + app->showMainWidget( mainWindow ); + } + } else { + owarn << "Could not create application main window" << oendl; + exit(-1); + } } private slots: void message(const QCString &msg, const QByteArray & data) { - QStrList argList; - - if ( msg == "execute(QStrList)" ) { - delete qlChannel; - QDataStream stream( data, IO_ReadOnly ); - QStrList argList; - stream >> argList; - qDebug( "QuickLauncher execute: %s", argList.at(0) ); - doQuickLaunch( argList ); - delete this; - } else if ( msg == "execute(QString)" ) { - delete qlChannel; - QDataStream stream( data, IO_ReadOnly ); - QString arg; - stream >> arg; - qDebug( "QuickLauncher execute: %s", arg.latin1() ); - QStrList argList; - argList.append( arg.utf8() ); - doQuickLaunch( argList ); - delete this; - } + QStrList argList; + + if ( msg == "execute(QStrList)" ) { + delete qlChannel; + QDataStream stream( data, IO_ReadOnly ); + QStrList argList; + stream >> argList; + odebug << "QuickLauncher execute: " << argList.at(0) << "" << oendl; + doQuickLaunch( argList ); + delete this; + } else if ( msg == "execute(QString)" ) { + delete qlChannel; + QDataStream stream( data, IO_ReadOnly ); + QString arg; + stream >> arg; + odebug << "QuickLauncher execute: " << arg << "" << oendl; + QStrList argList; + argList.append( arg.utf8() ); + doQuickLaunch( argList ); + delete this; + } } private: void doQuickLaunch( QStrList &argList ) { - static int myargc = argList.count(); - static char **myargv = new char *[myargc + 1]; - for ( int j = 0; j < myargc; j++ ) { - myargv[j] = new char [strlen(argList.at(j))+1]; - strcpy( myargv[j], argList.at(j) ); - } - myargv[myargc] = NULL; + static int myargc = argList.count(); + static char **myargv = new char *[myargc + 1]; + for ( int j = 0; j < myargc; j++ ) { + myargv[j] = new char [strlen(argList.at(j))+1]; + strcpy( myargv[j], argList.at(j) ); + } + myargv[myargc] = NULL; #ifdef _OS_LINUX_ - // Change name of process - setproctitle(myargv[0]); + // Change name of process + setproctitle(myargv[0]); #endif - connect(app, SIGNAL(lastWindowClosed()), app, SLOT(hideOrQuit())); - app->exit_loop(); - app->initApp( myargc, myargv ); - exec( myargc, myargv ); + connect(app, SIGNAL(lastWindowClosed()), app, SLOT(hideOrQuit())); + app->exit_loop(); + app->initApp( myargc, myargv ); + exec( myargc, myargv ); } private: QCopChannel *qlChannel; }; int main( int argc, char** argv ) { app = new QPEApplication( argc, argv ); loader = new PluginLoader( "application" ); unsetenv( "LD_BIND_NOW" ); QCString arg0 = argv[0]; int sep = arg0.findRev( '/' ); if ( sep > 0 ) - arg0 = arg0.mid( sep+1 ); + arg0 = arg0.mid( sep+1 ); if ( arg0 != "quicklauncher" ) { - qDebug( "QuickLauncher invoked as: %s", arg0.data() ); - QuickLauncher::exec( argc, argv ); + odebug << "QuickLauncher invoked as: " << arg0.data() << "" << oendl; + QuickLauncher::exec( argc, argv ); } else { #ifdef _OS_LINUX_ - // Setup to change proc title - int i; - char **envp = environ; - /* Move the environment so we can reuse the memory. - * (Code borrowed from sendmail.) */ - for (i = 0; envp[i] != NULL; i++) - continue; - environ = (char **) malloc(sizeof(char *) * (i + 1)); - if (environ == NULL) - return -1; - for (i = 0; envp[i] != NULL; i++) - if ((environ[i] = strdup(envp[i])) == NULL) - return -1; - environ[i] = NULL; - - argv0 = argv; - if (i > 0) - argv_lth = envp[i-1] + strlen(envp[i-1]) - argv0[0]; - else - argv_lth = argv0[argc-1] + strlen(argv0[argc-1]) - argv0[0]; + // Setup to change proc title + int i; + char **envp = environ; + /* Move the environment so we can reuse the memory. + * (Code borrowed from sendmail.) */ + for (i = 0; envp[i] != NULL; i++) + continue; + environ = (char **) malloc(sizeof(char *) * (i + 1)); + if (environ == NULL) + return -1; + for (i = 0; envp[i] != NULL; i++) + if ((environ[i] = strdup(envp[i])) == NULL) + return -1; + environ[i] = NULL; + + argv0 = argv; + if (i > 0) + argv_lth = envp[i-1] + strlen(envp[i-1]) - argv0[0]; + else + argv_lth = argv0[argc-1] + strlen(argv0[argc-1]) - argv0[0]; #endif - (void)new QuickLauncher(); - qDebug( "QuickLauncher running" ); - // Pre-load default fonts - QFontMetrics fm( QApplication::font() ); - fm.ascent(); // causes font load. - QFont f( QApplication::font() ); - f.setWeight( QFont::Bold ); - QFontMetrics fmb( f ); - fmb.ascent(); // causes font load. - - // Each of the following force internal structures/internal - // initialization to be performed. This may mean allocating - // memory that is not needed by all applications. + (void)new QuickLauncher(); + odebug << "QuickLauncher running" << oendl; + // Pre-load default fonts + QFontMetrics fm( QApplication::font() ); + fm.ascent(); // causes font load. + QFont f( QApplication::font() ); + f.setWeight( QFont::Bold ); + QFontMetrics fmb( f ); + fmb.ascent(); // causes font load. + + // Each of the following force internal structures/internal + // initialization to be performed. This may mean allocating + // memory that is not needed by all applications. #if 0 - TimeZone::current().isValid(); // popuplate timezone cache - TimeString::currentDateFormat(); // create internal structures - TimeString::currentAMPM(); + TimeZone::current().isValid(); // popuplate timezone cache + TimeString::currentDateFormat(); // create internal structures + TimeString::currentAMPM(); #endif - Resource::loadIconSet("new"); // do internal init + Resource::loadIconSet("new"); // do internal init /* make sure libopie gets lined in */ { Opie::Ui::OWait item; } - // Create a widget to force initialization of title bar images, etc. - QObject::disconnect(app, SIGNAL(lastWindowClosed()), app, SLOT(hideOrQuit())); - QWidget *w = new QWidget(0,0,Qt::WDestructiveClose|Qt::WStyle_ContextHelp|Qt::WStyle_Tool); - w->setGeometry( -100, -100, 10, 10 ); - w->show(); - QTimer::singleShot( 0, w, SLOT(close()) ); + // Create a widget to force initialization of title bar images, etc. + QObject::disconnect(app, SIGNAL(lastWindowClosed()), app, SLOT(hideOrQuit())); + QWidget *w = new QWidget(0,0,Qt::WDestructiveClose|Qt::WStyle_ContextHelp|Qt::WStyle_Tool); + w->setGeometry( -100, -100, 10, 10 ); + w->show(); + QTimer::singleShot( 0, w, SLOT(close()) ); - app->enter_loop(); + app->enter_loop(); } int rv = app->exec(); if ( mainWindow ) - delete (QWidget*)mainWindow; - + delete (QWidget*)mainWindow; + delete app; if ( appIface ) - loader->releaseInterface( appIface ); + loader->releaseInterface( appIface ); delete loader; // Neither QLibrary nor my Dropin is a QObject and they don't depend // on a qApp so we destroy QWidget::destroyMapper() without // crashing the app // // The problem is there are some 'static' resources not freed // in the apps and on destructing these objects are not available // anymore. In future fix up the apps but for now // we just skip deletion and hope things go well -zecke // delete app; // hack instead -zecke // delete app->pidChannel; // app->pidChannel = 0; return rv; } #include "main.moc" |