kitchensync

groupview.cpp
1 /*
2  This file is part of KitchenSync.
3 
4  Copyright (c) 2005 Cornelius Schumacher <schumacher@kde.org>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20 
21 #include <tqlayout.h>
22 
23 #include "aboutpage.h"
24 #include "groupitem.h"
25 #include "syncprocessmanager.h"
26 
27 #include "groupview.h"
28 
29 GroupView::GroupView( TQWidget *parent )
30  : TQWidget( parent ), mAboutPage( 0 )
31 {
32  mLayout = new TQVBoxLayout( this );
33 
34  mWidgetList = new KWidgetList( this );
35 
36  mLayout->addWidget( mWidgetList );
37 }
38 
39 SyncProcess* GroupView::selectedSyncProcess() const
40 {
41  GroupItem *item = static_cast<GroupItem*>( mWidgetList->selectedItem() );
42  if ( item )
43  return item->syncProcess();
44  else
45  return 0;
46 }
47 
48 void GroupView::clear()
49 {
50  mWidgetList->clear();
51 }
52 
53 void GroupView::updateView()
54 {
55  clear();
56 
57  if ( SyncProcessManager::self()->count() == 0 ) {
58  mWidgetList->hide();
59 
60  if ( !mAboutPage ) {
61  mAboutPage = new AboutPage( this );
62  mLayout->addWidget( mAboutPage );
63 
64  connect( mAboutPage, TQT_SIGNAL( addGroup() ), TQT_SIGNAL( addGroup() ) );
65  }
66 
67  mAboutPage->show();
68 
69  } else {
70  if ( mAboutPage )
71  mAboutPage->hide();
72  mWidgetList->show();
73  }
74 
75  for ( int i = 0; i < SyncProcessManager::self()->count(); ++i ) {
76  SyncProcess *process = SyncProcessManager::self()->at( i );
77 
78  GroupItem *item = new GroupItem( mWidgetList, process );
79  connect( item, TQT_SIGNAL( synchronizeGroup( SyncProcess* ) ),
80  TQT_SIGNAL( synchronizeGroup( SyncProcess* ) ) );
81  connect( item, TQT_SIGNAL( abortSynchronizeGroup( SyncProcess* ) ),
82  TQT_SIGNAL( abortSynchronizeGroup( SyncProcess* ) ) );
83  connect( item, TQT_SIGNAL( configureGroup( SyncProcess* ) ),
84  TQT_SIGNAL( configureGroup( SyncProcess* ) ) );
85 
86  mWidgetList->appendItem( item );
87  }
88 }
89 
90 void GroupView::updateSyncProcess( SyncProcess *syncProcess )
91 {
92  for ( int i = 0; i < (int)mWidgetList->count(); ++i ) {
93  GroupItem *item = static_cast<GroupItem*>( mWidgetList->item( i ) );
94  if ( item && item->syncProcess() == syncProcess )
95  item->update();
96  }
97 }
98 
99 #include "groupview.moc"