~ubuntu-branches/ubuntu/oneiric/kdepim/oneiric-updates

« back to all changes in this revision

Viewing changes to kresources/lib/folderconfig.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-06-28 19:33:24 UTC
  • mfrom: (0.2.13) (0.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20110628193324-8yvjs8sdv9rdoo6c
Tags: 4:4.7.0-0ubuntu1
* New upstream release
  - update install files
  - add missing kdepim-doc package to control file
  - Fix Vcs lines
  - kontact breaks/replaces korganizer << 4:4.6.80
  - tighten the dependency of kdepim-dev on libkdepim4 to fix lintian error

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    This file is part of libkcal.
3
 
 
4
 
    Copyright (c) 2004 Cornelius Schumacher <schumacher@kde.org>
5
 
    Copyright (c) 2004 Till Adam <adam@kde.org>
6
 
    Copyright (c) 2005 Reinhold Kainhofer <reinhold@kainhofer.com>
7
 
 
8
 
    This library is free software; you can redistribute it and/or
9
 
    modify it under the terms of the GNU Library General Public
10
 
    License as published by the Free Software Foundation; either
11
 
    version 2 of the License, or (at your option) any later version.
12
 
    
13
 
    This library is distributed in the hope that it will be useful,
14
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 
    Library General Public License for more details.
17
 
    
18
 
    You should have received a copy of the GNU Library General Public License
19
 
    along with this library; see the file COPYING.LIB.  If not, write to
20
 
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21
 
    Boston, MA 02110-1301, USA.
22
 
*/
23
 
 
24
 
#include "folderconfig.h"
25
 
 
26
 
#include "folderlister.h"
27
 
#include "groupwaredataadaptor.h"
28
 
#include "folderlistview.h"
29
 
 
30
 
#include <k3listview.h>
31
 
#include <klocale.h>
32
 
#include <kdebug.h>
33
 
#include <kdialog.h>
34
 
 
35
 
#include <QLayout>
36
 
#include <q3groupbox.h>
37
 
#include <QPushButton>
38
 
#include <QComboBox>
39
 
#include <QLabel>
40
 
//Added by qt3to4:
41
 
#include <QVBoxLayout>
42
 
#include <QBoxLayout>
43
 
#include <Q3PtrList>
44
 
 
45
 
using namespace KPIM;
46
 
 
47
 
FolderConfig::FolderConfig( QWidget *parent )
48
 
  : QWidget( parent ), mFolderLister( 0 )
49
 
{
50
 
  QBoxLayout *topLayout = new QVBoxLayout( this );
51
 
  topLayout->addSpacing( KDialog::spacingHint() );
52
 
 
53
 
  Q3GroupBox *topBox = new Q3GroupBox( 1, Qt::Horizontal, i18n("Folder Selection"),
54
 
    this );
55
 
  topLayout->addWidget( topBox );
56
 
  
57
 
  QPushButton *button = new QPushButton( i18n("Update Folder List"), topBox );
58
 
  connect( button, SIGNAL( clicked() ), SIGNAL( updateFoldersClicked() ) );
59
 
  
60
 
  mFolderList = new FolderListView( topBox );
61
 
 
62
 
/*  QHBox *writeBox = new QHBox( topBox );
63
 
 
64
 
  new QLabel( i18n("Write to:"), writeBox );
65
 
  
66
 
  mWriteCombo = new QComboBox( writeBox );*/
67
 
}
68
 
 
69
 
FolderConfig::~FolderConfig()
70
 
{
71
 
}
72
 
 
73
 
void FolderConfig::setFolderLister( FolderLister *f )
74
 
{
75
 
  mFolderLister = f;
76
 
  
77
 
  QList<FolderListView::Property> types;
78
 
  QList<FolderLister::ContentType> suptypes( mFolderLister->supportedTypes() );
79
 
  if ( suptypes.contains( FolderLister::Event ) ) types << FolderListView::Event;
80
 
  if ( suptypes.contains( FolderLister::Todo ) ) types << FolderListView::Todo;
81
 
  if ( suptypes.contains( FolderLister::Journal ) ) types << FolderListView::Journal;
82
 
  if ( suptypes.contains( FolderLister::Contact ) ) types << FolderListView::Contact;
83
 
  if ( suptypes.contains( FolderLister::All ) ) types << FolderListView::All;
84
 
  if ( suptypes.contains( FolderLister::Unknown ) ) types << FolderListView::Unknown;
85
 
 
86
 
  mFolderList->setEnabledTypes( types );
87
 
  connect( mFolderLister, SIGNAL( foldersRead() ), SLOT( updateFolderList() ) );
88
 
}
89
 
 
90
 
void FolderConfig::retrieveFolderList( const KUrl &url )
91
 
{
92
 
  kDebug(7000) <<"FolderConfig::retrieveFolderList()";
93
 
  if ( !mOldFolderListerURL.isEmpty() ) return;
94
 
 
95
 
  if ( mFolderLister->adaptor() ) {
96
 
    mOldFolderListerURL = mFolderLister->adaptor()->baseURL();
97
 
    mFolderLister->adaptor()->setBaseURL( url );
98
 
  }
99
 
  mFolderLister->retrieveFolders( url );
100
 
}
101
 
 
102
 
void FolderConfig::updateFolderList()
103
 
{
104
 
  mFolderList->clear();
105
 
 
106
 
  QStringList write;
107
 
 
108
 
  if ( !mOldFolderListerURL.isEmpty() && mFolderLister->adaptor() ) {
109
 
    mFolderLister->adaptor()->setBaseURL( mOldFolderListerURL );
110
 
    mOldFolderListerURL = KUrl();
111
 
  }
112
 
 
113
 
  FolderLister::Entry::List folders = mFolderLister->folders();
114
 
  FolderLister::Entry::List::ConstIterator it;
115
 
  for( it = folders.constBegin(); it != folders.constEnd(); ++it ) {
116
 
    FolderListItem *item = new FolderListItem( mFolderList, (*it) );
117
 
    if ( mFolderLister->writeDestinationId( FolderLister::Event ) == (*it).id ) {
118
 
      item->setDefault( FolderListView::Event );
119
 
    }
120
 
    if ( mFolderLister->writeDestinationId( FolderLister::Todo ) == (*it).id ) {
121
 
      item->setDefault( FolderListView::Todo );
122
 
    }
123
 
    if ( mFolderLister->writeDestinationId( FolderLister::Journal ) == (*it).id ) {
124
 
      item->setDefault( FolderListView::Journal );
125
 
    }
126
 
    if ( mFolderLister->writeDestinationId( FolderLister::Contact ) == (*it).id ) {
127
 
      item->setDefault( FolderListView::Contact );
128
 
    }
129
 
    if ( mFolderLister->writeDestinationId( FolderLister::All ) == (*it).id ) {
130
 
      item->setDefault( FolderListView::All );
131
 
    }
132
 
    if ( mFolderLister->writeDestinationId( FolderLister::Unknown ) == (*it).id ) {
133
 
      item->setDefault( FolderListView::Unknown );
134
 
    }
135
 
  }
136
 
}
137
 
 
138
 
void FolderConfig::saveSettings()
139
 
{
140
 
  Q3PtrList<Q3ListViewItem> lst;
141
 
 
142
 
  FolderLister::Entry::List folders;
143
 
 
144
 
  Q3ListViewItemIterator it( mFolderList );
145
 
  while ( it.current() ) {
146
 
    FolderListItem *item = dynamic_cast<FolderListItem *>( it.current() );
147
 
    if ( item ) {
148
 
      FolderLister::Entry folder = item->folder();
149
 
      folder.active = item->isOn();
150
 
      folders.append( folder );
151
 
      if ( item->isDefault( FolderListView::Event ) ) {
152
 
        mFolderLister->setWriteDestinationId( FolderLister::Event, folder.id );
153
 
      }
154
 
      if ( item->isDefault( FolderListView::Todo ) ) {
155
 
        mFolderLister->setWriteDestinationId( FolderLister::Todo, folder.id );
156
 
      }
157
 
      if ( item->isDefault( FolderListView::Journal ) ) {
158
 
        mFolderLister->setWriteDestinationId( FolderLister::Journal, folder.id );
159
 
      }
160
 
      if ( item->isDefault( FolderListView::Contact ) ) {
161
 
        mFolderLister->setWriteDestinationId( FolderLister::Contact, folder.id );
162
 
      }
163
 
      if ( item->isDefault( FolderListView::All ) ) {
164
 
        mFolderLister->setWriteDestinationId( FolderLister::All, folder.id );
165
 
      }
166
 
      if ( item->isDefault( FolderListView::Unknown ) ) {
167
 
        mFolderLister->setWriteDestinationId( FolderLister::Unknown, folder.id );
168
 
      }
169
 
    }
170
 
    ++it;
171
 
  }
172
 
 
173
 
  mFolderLister->setFolders( folders );
174
 
}
175
 
 
176
 
#include "folderconfig.moc"