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

« back to all changes in this revision

Viewing changes to kmail/localsubscriptiondialog.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
 
/*  -*- c++ -*-
2
 
  localsubscriptiondialog.cpp
3
 
 
4
 
  This file is part of KMail, the KDE mail client.
5
 
  Copyright (C) 2006 Till Adam <adam@kde.org>
6
 
 
7
 
  KMail is free software; you can redistribute it and/or modify it
8
 
  under the terms of the GNU General Public License, version 2, as
9
 
  published by the Free Software Foundation.
10
 
 
11
 
  KMail is distributed in the hope that it will be useful, but
12
 
  WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 
  General Public License for more details.
15
 
 
16
 
  You should have received a copy of the GNU General Public License along
17
 
  with this program; if not, write to the Free Software Foundation, Inc.,
18
 
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
 
 
20
 
  In addition, as a special exception, the copyright holders give
21
 
  permission to link the code of this program with any edition of
22
 
  the Qt library by Trolltech AS, Norway (or with modified versions
23
 
  of Qt that use the same license as Qt), and distribute linked
24
 
  combinations including the two.  You must obey the GNU General
25
 
  Public License in all respects for all of the code used other than
26
 
  Qt.  If you modify this file, you may extend this exception to
27
 
  your version of the file, but you are not obligated to do so.  If
28
 
  you do not wish to do so, delete this exception statement from
29
 
  your version.
30
 
*/
31
 
 
32
 
#include "localsubscriptiondialog.h"
33
 
 
34
 
#include <kdebug.h>
35
 
#include <klocale.h>
36
 
#include <kmessagebox.h>
37
 
 
38
 
#include "kmkernel.h"
39
 
#include "accountmanager.h"
40
 
#include "kmmessage.h"
41
 
#include "imapaccountbase.h"
42
 
#include "listjob.h"
43
 
 
44
 
namespace KMail {
45
 
 
46
 
LocalSubscriptionDialog::LocalSubscriptionDialog( QWidget *parent, const QString &caption,
47
 
    ImapAccountBase *acct, const QString &startPath )
48
 
  : SubscriptionDialog( parent, caption, acct, startPath ),
49
 
    mAccount( acct )
50
 
{
51
 
}
52
 
 
53
 
/* virtual */
54
 
LocalSubscriptionDialog::~LocalSubscriptionDialog()
55
 
{
56
 
 
57
 
}
58
 
 
59
 
void LocalSubscriptionDialog::listAllAvailableAndCreateItems()
60
 
{
61
 
  if ( mAccount->onlySubscribedFolders() )
62
 
    mSubscribed = true;
63
 
  SubscriptionDialog::listAllAvailableAndCreateItems();
64
 
}
65
 
 
66
 
/* virtual */
67
 
void LocalSubscriptionDialog::processFolderListing()
68
 
{
69
 
  uint done = 0;
70
 
  for (int i = mCount; i < mFolderNames.count(); ++i)
71
 
  {
72
 
    // give the dialog a chance to repaint
73
 
    if (done == 1000)
74
 
    {
75
 
      emit listChanged();
76
 
      QTimer::singleShot(0, this, SLOT(processItems()));
77
 
      return;
78
 
    }
79
 
    ++mCount;
80
 
    ++done;
81
 
    createListViewItem( i );
82
 
  }
83
 
 
84
 
  if ( mPrefixList.isEmpty() && !mSubscribed )
85
 
    loadingComplete(); // no need to load subscribed folders
86
 
  else
87
 
    processNext();
88
 
}
89
 
 
90
 
void LocalSubscriptionDialog::setCheckedStateOfAllItems()
91
 
{
92
 
   // iterate over all items and check them, unless they are
93
 
   // in the account's local subscription blacklist
94
 
  QMapIterator<QString, GroupItem*> it( mItemDict );
95
 
  while ( it.hasNext() ) {
96
 
    it.next();
97
 
    QString path = it.key();
98
 
    GroupItem *item = it.value();
99
 
    item->setOn( mAccount->locallySubscribedTo( path ) );
100
 
  }
101
 
}
102
 
 
103
 
/*virtual*/
104
 
bool LocalSubscriptionDialog::doSave()
105
 
{
106
 
  if ( !checkIfSubscriptionsEnabled() )
107
 
    return false;
108
 
 
109
 
  bool somethingHappened = false;
110
 
  // subscribe
111
 
  QTreeWidgetItemIterator it(subView);
112
 
  for ( ; *it; ++it) {
113
 
    static_cast<ImapAccountBase*>(account())->changeLocalSubscription(
114
 
        static_cast<GroupItem*>(*it)->info().path, true );
115
 
    somethingHappened = true;
116
 
  }
117
 
 
118
 
  // unsubscribe
119
 
  QTreeWidgetItemIterator it2(unsubView);
120
 
  if ( unsubView->topLevelItemCount() > 0 ) {
121
 
    const QString message = i18nc( "@info", "Locally unsubscribing from folders will remove all "
122
 
        "information that is present locally about those folders. The folders will "
123
 
        "not be changed on the server. Press cancel now if you want to make sure "
124
 
        "all local changes have been written to the server by checking mail first.");
125
 
    const QString caption = i18nc( "@title:window", "Local changes will be lost when "
126
 
                                  "unsubscribing" );
127
 
    if ( KMessageBox::warningContinueCancel( this, message, caption )
128
 
        != KMessageBox::Cancel ) {
129
 
      somethingHappened = true;
130
 
      for ( ; *it2; ++it2) {
131
 
        static_cast<ImapAccountBase*>(account())->changeLocalSubscription(
132
 
            static_cast<GroupItem*>(*it2)->info().path, false );
133
 
      }
134
 
 
135
 
    }
136
 
  }
137
 
 
138
 
  // Slight code duplication with SubscriptionDialog follows!
139
 
  KMail::ImapAccountBase *a = static_cast<KMail::ImapAccountBase*>( mAcct );
140
 
  if ( mForceSubscriptionEnable ) {
141
 
    a->setOnlyLocallySubscribedFolders( true );
142
 
  }
143
 
 
144
 
  if ( somethingHappened && subscriptionOptionEnabled( a ) ) {
145
 
    kmkernel->acctMgr()->singleCheckMail( mAccount, true);
146
 
  }
147
 
 
148
 
  return true;
149
 
}
150
 
 
151
 
bool LocalSubscriptionDialog::subscriptionOptionEnabled( const KMail::ImapAccountBase *account ) const
152
 
{
153
 
  return account->onlyLocallySubscribedFolders();
154
 
}
155
 
 
156
 
QString LocalSubscriptionDialog::subscriptionOptionQuestion( const QString &accountName ) const
157
 
{
158
 
  return i18nc( "@info", "Currently local subscriptions are not used for account <resource>%1</resource>.<nl/>"
159
 
      "\nDo you want to enable local subscriptions?", accountName );
160
 
}
161
 
 
162
 
void LocalSubscriptionDialog::loadingComplete()
163
 
{
164
 
  setCheckedStateOfAllItems();
165
 
  SubscriptionDialog::loadingComplete();
166
 
}
167
 
 
168
 
} // namespace
169
 
 
170
 
#include "localsubscriptiondialog.moc"