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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* -*- mode: C++; c-file-style: "gnu" -*-
  This file is part of KMail, the KDE mail client.
  Copyright (c) 1997 Markus Wuebben <markus.wuebben@kde.org>
  Copyright (c) 2007 Thomas McGuire <Thomas.McGuire@gmx.net>

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License along
  with this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#include "kmatmlistview.h"


#include <QWidget>
#include <QCheckBox>
#include <QHBoxLayout>

#include "attachmentlistview.h"

KMAtmListViewItem::KMAtmListViewItem( KMail::AttachmentListView *parent,
                                      KMMessagePart* attachment )
  : QObject(),
    QTreeWidgetItem( parent ),
    mAttachment( attachment ),
    mParent( parent )

{
  mCBCompress = addCheckBox( 4 );
  mCBEncrypt = addCheckBox( 5 );
  mCBSign = addCheckBox( 6 );

  connect( mCBCompress, SIGNAL( clicked() ), this, SLOT( slotCompress() ) );
}

// This function was also copied to
// QRadioButton* KMPopHeadersViewItem::addRadioButton( int column )
QCheckBox* KMAtmListViewItem::addCheckBox( int column )
{
  // We can not call setItemWidget() on the checkbox directly, because then
  // the checkbox would be left-aligned. Therefore we create a helper widget
  // with a layout to align the checkbox to the center.
  QWidget *w = new QWidget( treeWidget() );
  QCheckBox *c = new QCheckBox();
  QHBoxLayout *l = new QHBoxLayout();
  l->insertWidget( 0, c, 0, Qt::AlignHCenter );
  w->setBackgroundRole( QPalette::Base );
  c->setBackgroundRole( QPalette::Base );
  w->setLayout( l );
  l->setMargin( 0 );
  l->setSpacing( 0 );
  w->show();
  treeWidget()->setItemWidget( this, column, w );
  return c;
}

KMAtmListViewItem::~KMAtmListViewItem()
{
  // The checkboxes should be automatically deleted by the treewidget
  mCBEncrypt = 0;
  mCBSign = 0;
  mCBCompress = 0;
}

bool KMAtmListViewItem::operator < ( const QTreeWidgetItem & other ) const
{
  if ( treeWidget()->sortColumn() != 1 )
    return QTreeWidgetItem::operator < ( other );
  else
    return mAttachmentSize <
        (static_cast<const KMAtmListViewItem*>( &other ))->mAttachmentSize;
}

void KMAtmListViewItem::setEncrypt( bool on )
{
  if ( mCBEncrypt ) {
    mCBEncrypt->setChecked( on );
  }
}

bool KMAtmListViewItem::isEncrypt() const
{
  if ( mParent->areCryptoCBsEnabled() ) {
    return mCBEncrypt->isChecked();
  } else {
    return false;
  }
}

void KMAtmListViewItem::setSign( bool on )
{
  if ( mCBSign ) {
    mCBSign->setChecked( on );
  }
}

bool KMAtmListViewItem::isSign() const
{
  if ( mParent->areCryptoCBsEnabled() ) {
    return mCBSign->isChecked();
  } else {
    return false;
  }
}

void KMAtmListViewItem::setCompress( bool on )
{
  mCBCompress->setChecked( on );
}

bool KMAtmListViewItem::isCompress() const
{
  return mCBCompress->isChecked();
}

void KMAtmListViewItem::slotCompress()
{
  if ( mCBCompress->isChecked() ) {
    emit compress( this );
  } else {
    emit uncompress( this );
  }
}

KMMessagePart* KMAtmListViewItem::attachment() const
{
  return mAttachment;
}


#include "kmatmlistview.moc"