~ubuntu-branches/ubuntu/karmic/kdepim/karmic-backports

« back to all changes in this revision

Viewing changes to akonadi/kresources/shared/storecollectiondialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi, Alessandro Ghersi, Harald Sitter
  • Date: 2009-06-27 04:40:05 UTC
  • mfrom: (1.1.39 upstream)
  • Revision ID: james.westby@ubuntu.com-20090627044005-4y2vm9xz7rvmzi4p
Tags: 4:4.2.95svn20090701-0ubuntu1
[ Alessandro Ghersi ]
* New upstream release
  - Bump build-deps
* Remove akonadi-kde and libmaildir4 packages
  - remove akonadi-kde.install and libmaildir4.install
  - remove libmaildir4 from debian/rules
  - remove akonadi-kde and libmaildir4 from depends
  - remove akonadi-kde and libmaildir4 from installgen
* Update kdepim-dev.install
* Update kpilot.install
* Add akonadi-kde and libmaildir4 transitional packages

[ Harald Sitter ]
* KAddressbook replaces Kontact << 4.2.85 (LP: #378373)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    This file is part of kdepim.
 
3
    Copyright (c) 2009 Kevin Krammer <kevin.krammer@gmx.at>
 
4
 
 
5
    This library is free software; you can redistribute it and/or
 
6
    modify it under the terms of the GNU Library General Public
 
7
    License as published by the Free Software Foundation; either
 
8
    version 2 of the License, or (at your option) any later version.
 
9
 
 
10
    This library is distributed in the hope that it will be useful,
 
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
    Library General Public License for more details.
 
14
 
 
15
    You should have received a copy of the GNU Library General Public License
 
16
    along with this library; see the file COPYING.LIB.  If not, write to
 
17
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
18
    Boston, MA 02110-1301, USA.
 
19
*/
 
20
 
 
21
#include "storecollectiondialog.h"
 
22
 
 
23
#include "storecollectionfilterproxymodel.h"
 
24
 
 
25
#include <akonadi/collectionmodel.h>
 
26
#include <akonadi/collectionview.h>
 
27
 
 
28
#include <KLocale>
 
29
 
 
30
#include <QLabel>
 
31
#include <QVBoxLayout>
 
32
 
 
33
using namespace Akonadi;
 
34
 
 
35
static QModelIndex findCollection( const Collection &collection,
 
36
        const QModelIndex &parent, QAbstractItemModel *model)
 
37
{
 
38
  const int rowCount = model->rowCount( parent );
 
39
 
 
40
  for ( int row = 0; row < rowCount; ++row ) {
 
41
    QModelIndex index = model->index( row, 0, parent );
 
42
    if ( !index.isValid() )
 
43
      continue;
 
44
 
 
45
    QVariant data = model->data( index, CollectionModel::CollectionIdRole );
 
46
    if ( !data.isValid() )
 
47
      continue;
 
48
 
 
49
    if ( data.toInt() == collection.id() ) {
 
50
      return index;
 
51
    }
 
52
 
 
53
    index = findCollection( collection, index, model );
 
54
    if ( index.isValid() )
 
55
      return index;
 
56
  }
 
57
 
 
58
  return QModelIndex();
 
59
}
 
60
 
 
61
StoreCollectionDialog::StoreCollectionDialog( QWidget* parent )
 
62
  : KDialog( parent ),
 
63
    mLabel( 0 ),
 
64
    mFilterModel( 0 ),
 
65
    mView( 0 )
 
66
{
 
67
  setCaption( i18nc( "@title:window", "Target Folder Selection") );
 
68
 
 
69
  setButtons( KDialog::Ok | KDialog::Cancel );
 
70
 
 
71
  CollectionModel *model = new CollectionModel( this );
 
72
 
 
73
  QWidget *widget = new QWidget( this );
 
74
 
 
75
  QVBoxLayout *mainLayout = new QVBoxLayout( widget );
 
76
  mainLayout->setMargin( KDialog::marginHint() );
 
77
  mainLayout->setSpacing( KDialog::spacingHint() );
 
78
 
 
79
  // initially hide label until a text is set
 
80
  mLabel = new QLabel( widget );
 
81
  mLabel->hide();
 
82
 
 
83
  mainLayout->addWidget( mLabel );
 
84
 
 
85
  mFilterModel = new StoreCollectionFilterProxyModel( this );
 
86
  mFilterModel->setSourceModel( model );
 
87
 
 
88
  mView = new CollectionView( widget );
 
89
  mView->setSelectionMode( QAbstractItemView::SingleSelection );
 
90
  mView->setModel( mFilterModel );
 
91
 
 
92
  connect( mView, SIGNAL( currentChanged( const Akonadi::Collection& ) ),
 
93
           this, SLOT( collectionChanged( const Akonadi::Collection& ) ) );
 
94
  connect( mView->model(), SIGNAL( rowsInserted( const QModelIndex&, int, int ) ),
 
95
           this, SLOT( collectionsInserted( const QModelIndex&, int, int ) ) );
 
96
 
 
97
  mainLayout->addWidget( mView );
 
98
 
 
99
  setMainWidget( widget );
 
100
}
 
101
 
 
102
StoreCollectionDialog::~StoreCollectionDialog()
 
103
{
 
104
}
 
105
 
 
106
void StoreCollectionDialog::setLabelText( const QString &labelText )
 
107
{
 
108
  mLabel->setText( labelText );
 
109
  mLabel->show();
 
110
}
 
111
 
 
112
void StoreCollectionDialog::setMimeType( const QString &mimeType )
 
113
{
 
114
  mFilterModel->clearFilters();
 
115
  mFilterModel->addMimeTypeFilter( mimeType );
 
116
}
 
117
 
 
118
void StoreCollectionDialog::setSelectedCollection( const Collection &collection )
 
119
{
 
120
  mSelectedCollection = collection;
 
121
 
 
122
  QModelIndex index = findCollection( mSelectedCollection, mView->rootIndex(), mView->model() );
 
123
  if ( index.isValid() ) {
 
124
    mView->setCurrentIndex( index );
 
125
  }
 
126
}
 
127
 
 
128
Collection StoreCollectionDialog::selectedCollection() const
 
129
{
 
130
  return mSelectedCollection;
 
131
}
 
132
 
 
133
void StoreCollectionDialog::setSubResourceModel( const AbstractSubResourceModel *subResourceModel )
 
134
{
 
135
  mFilterModel->setSubResourceModel( subResourceModel );
 
136
}
 
137
 
 
138
void StoreCollectionDialog::collectionChanged( const Collection &collection )
 
139
{
 
140
  mSelectedCollection = collection;
 
141
}
 
142
 
 
143
void StoreCollectionDialog::collectionsInserted( const QModelIndex &parent, int start, int end )
 
144
{
 
145
  QAbstractItemModel *model = mView->model();
 
146
 
 
147
  for ( int row = start; row <= end; ++row ) {
 
148
    QModelIndex index = model->index( row, 0, parent );
 
149
    if ( !index.isValid() )
 
150
      continue;
 
151
 
 
152
    QVariant data = model->data( index, CollectionModel::CollectionIdRole );
 
153
    if ( !data.isValid() )
 
154
      continue;
 
155
 
 
156
    if ( data.toLongLong() == mSelectedCollection.id() ) {
 
157
      mView->setCurrentIndex( index );
 
158
      return;
 
159
    }
 
160
 
 
161
    index = findCollection( mSelectedCollection, index, model );
 
162
    if ( index.isValid() ) {
 
163
      mView->setCurrentIndex( index );
 
164
      return;
 
165
    }
 
166
  }
 
167
}
 
168
 
 
169
// kate: space-indent on; indent-width 2; replace-tabs on;