kitchensync

overviewwidget.cpp

00001 /*
00002     This file is part of KitchenSync.
00003 
00004     Copyright (c) 2002 Holger Freyther <zecke@handhelds.org>
00005     Copyright (c) 2002 Maximilian Reiß <harlekin@handhelds.org>
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Library General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Library General Public License for more details.
00016 
00017     You should have received a copy of the GNU Library General Public License
00018     along with this library; see the file COPYING.LIB.  If not, write to
00019     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020     Boston, MA 02110-1301, USA.
00021 */
00022 
00023 #include <qdatetime.h>
00024 #include <qsplitter.h>
00025 #include <qtextedit.h>
00026 #include <qvbox.h>
00027 
00028 #include <kconfig.h>
00029 #include <kdialog.h>
00030 #include <klocale.h>
00031 
00032 #include <actionpart.h>
00033 
00034 #include "overviewwidget.h"
00035 
00036 using namespace KSync;
00037 using namespace KSync::OverView;
00038 
00039 Widget::Widget( QWidget* parent, const char* name )
00040   : QWidget( parent, name )
00041 {
00042   QVBoxLayout *layout = new QVBoxLayout( this );
00043   layout->setMargin( KDialog::marginHint() );
00044 
00045   QHBox* info = new QHBox( this );
00046   info->setSpacing( 10 );
00047   info->setMargin( 10 );
00048 
00049   QVBox *info2 = new QVBox(info);
00050   m_device = new QLabel( info2 );
00051   m_profile= new QLabel( info2 );
00052   info->setStretchFactor( info2, 5 );
00053 
00054   m_logo = new QLabel( info );
00055 
00056   m_split = new QSplitter( this );
00057   m_edit = new QTextEdit( m_split );
00058   m_edit->setReadOnly( true );
00059   m_edit->setTextFormat( Qt::LogText );
00060   m_ab = new QWidget( m_split );
00061 
00062   KConfig config( "kitchensyncrc" );
00063   config.setGroup( "OverviewPart" );
00064 
00065   QValueList<int> sizes = config.readIntListEntry( "SplitterSize" );
00066   if ( sizes.isEmpty() ) {
00067     sizes.append( width() / 2 );
00068     sizes.append( width() / 2 );
00069   }
00070 
00071   m_split->setSizes( sizes );
00072 
00073   m_layout = new QVBoxLayout( m_ab );
00074   m_layout->insertStretch( -1, 5 );
00075   m_layoutFillIndex = 0;
00076 
00077   layout->addWidget( info );
00078   layout->addWidget( m_split, 100 );
00079 
00080   m_messageList.setAutoDelete( true );
00081 }
00082 
00083 Widget::~Widget()
00084 {
00085   KConfig config( "kitchensyncrc" );
00086   config.setGroup( "OverviewPart" );
00087 
00088   config.writeEntry( "SplitterSize", m_split->sizes() );
00089 }
00090 
00091 void Widget::setProfile( const Profile& prof )
00092 {
00093   m_profile->setText( "<qt><b>" + i18n( " Profile: " ) + "</b>" + prof.name() + "</qt>" );
00094   cleanView();
00095 }
00096 
00097 void Widget::setProfile( const QString& name, const QPixmap& pix )
00098 {
00099   m_device->setText( "<qt><b>"+ i18n( " Device: " ) + "</b>" + name + "</qt>" );
00100   m_logo->setPixmap( pix );
00101   cleanView();
00102 }
00103 
00104 void Widget::syncProgress( ActionPart * part, int status, int )
00105 {
00106   OverViewProgressEntry* it;
00107   for ( it = m_messageList.first(); it; it = m_messageList.next() ) {
00108     if ( QString::compare( it->name(), part->name() ) == 0 ) {
00109       it->setProgress( status );
00110       return;
00111     }
00112   }
00113 
00114   OverViewProgressEntry* test = new OverViewProgressEntry( m_ab, "test" );
00115   m_messageList.append( test );
00116 
00117   if ( !part->title().isEmpty() )  {
00118     test->setText( part->title() );
00119   }
00120 
00121   if ( part->pixmap() ) {
00122     test->setPixmap( *(part->pixmap()) );
00123   }
00124 
00125   test->setProgress( status );
00126   m_layout->insertWidget( m_layoutFillIndex , test, 0, AlignTop );
00127   m_layoutFillIndex++;
00128   test->show();
00129 }
00130 
00131 void Widget::startSync()
00132 {
00133   m_edit->append( "Starting to sync now" );
00134 }
00135 
00136 void Widget::cleanView()
00137 {
00138   m_messageList.clear();
00139 }
00140 
00141 #include "overviewwidget.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys