~ubuntu-branches/ubuntu/raring/kdepim/raring-proposed

« back to all changes in this revision

Viewing changes to mailcommon/filter/filteractionwithfolder.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2012-06-07 07:56:38 UTC
  • mfrom: (0.2.27)
  • Revision ID: package-import@ubuntu.com-20120607075638-0luhdq11z7sgvs4m
Tags: 4:4.8.80-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 1996-1998 Stefan Taferner <taferner@kde.org>
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
17
 *
 
18
 */
 
19
 
 
20
#include "filteractionwithfolder.h"
 
21
 
 
22
#include "../folderrequester.h"
 
23
#include "../mailkernel.h"
 
24
#include "../mailutil.h"
 
25
#include "filteractionmissingargumentdialog.h"
 
26
 
 
27
#include <QtGui/QTextDocument>
 
28
 
 
29
using namespace MailCommon;
 
30
 
 
31
FilterActionWithFolder::FilterActionWithFolder( const char *name, const QString &label, QObject *parent )
 
32
  : FilterAction( name, label, parent )
 
33
{
 
34
}
 
35
 
 
36
bool FilterActionWithFolder::isEmpty() const
 
37
{
 
38
  return !mFolder.isValid();
 
39
}
 
40
 
 
41
QWidget* FilterActionWithFolder::createParamWidget( QWidget *parent ) const
 
42
{
 
43
  FolderRequester *requester = new FolderRequester( parent );
 
44
  requester->setShowOutbox( false );
 
45
  setParamWidgetValue( requester );
 
46
 
 
47
  connect( requester, SIGNAL(folderChanged(Akonadi::Collection)),
 
48
           this, SIGNAL(filterActionModified()) );
 
49
 
 
50
  return requester;
 
51
}
 
52
 
 
53
void FilterActionWithFolder::applyParamWidgetValue( QWidget *paramWidget )
 
54
{
 
55
  mFolder = static_cast<FolderRequester*>( paramWidget )->collection();
 
56
}
 
57
 
 
58
void FilterActionWithFolder::setParamWidgetValue( QWidget *paramWidget ) const
 
59
{
 
60
  static_cast<FolderRequester*>( paramWidget )->setCollection( mFolder );
 
61
}
 
62
 
 
63
void FilterActionWithFolder::clearParamWidget( QWidget *paramWidget ) const
 
64
{
 
65
  static_cast<FolderRequester*>( paramWidget )->setCollection( CommonKernel->draftsCollectionFolder() );
 
66
}
 
67
 
 
68
bool FilterActionWithFolder::argsFromStringInteractive( const QString &argsStr , const QString& name)
 
69
{
 
70
  bool needUpdate = false;
 
71
  argsFromString( argsStr );
 
72
  if ( !mFolder.isValid() ) {
 
73
    bool exactPath = false;
 
74
    Akonadi::Collection::List lst = FilterActionMissingCollectionDialog::potentialCorrectFolders( argsStr, exactPath );
 
75
    if ( lst.count() == 1 && exactPath )
 
76
      mFolder = lst.at( 0 );
 
77
    else {
 
78
      FilterActionMissingCollectionDialog *dlg = new FilterActionMissingCollectionDialog( lst, name, argsStr );
 
79
      if ( dlg->exec() ) {
 
80
        mFolder = dlg->selectedCollection();
 
81
        needUpdate = true;
 
82
      }
 
83
      delete dlg;
 
84
    }
 
85
  }
 
86
  return needUpdate;
 
87
}
 
88
 
 
89
QString FilterActionWithFolder::argsAsStringReal() const
 
90
{
 
91
  if ( KernelIf->collectionModel() )
 
92
    return MailCommon::Util::fullCollectionPath( mFolder );
 
93
  return FilterActionWithFolder::argsAsString();
 
94
}
 
95
 
 
96
void FilterActionWithFolder::argsFromString( const QString &argsStr )
 
97
{
 
98
  bool ok = false;
 
99
  const Akonadi::Collection::Id id = argsStr.toLongLong( &ok );
 
100
  if ( ok ) {
 
101
    mFolder = Akonadi::Collection( id );
 
102
  } else {
 
103
    mFolder = Akonadi::Collection();
 
104
  }
 
105
}
 
106
 
 
107
QString FilterActionWithFolder::argsAsString() const
 
108
{
 
109
  QString result;
 
110
  if ( mFolder.isValid() )
 
111
    result = QString::number( mFolder.id() );
 
112
 
 
113
  return result;
 
114
}
 
115
 
 
116
QString FilterActionWithFolder::displayString() const
 
117
{
 
118
  QString result;
 
119
  if ( mFolder.isValid() )
 
120
    result = MailCommon::Util::fullCollectionPath(MailCommon::Util::updatedCollection( mFolder ));
 
121
 
 
122
  return label() + QLatin1String( " \"" ) + Qt::escape( result ) + QLatin1String( "\"" );
 
123
}
 
124
 
 
125
bool FilterActionWithFolder::folderRemoved( const Akonadi::Collection &oldFolder, const Akonadi::Collection &newFolder )
 
126
{
 
127
  if ( oldFolder == mFolder ) {
 
128
    mFolder = newFolder;
 
129
    return true;
 
130
  } else
 
131
    return false;
 
132
}
 
133
 
 
134
 
 
135
#include "filteractionwithfolder.moc"