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

« back to all changes in this revision

Viewing changes to knode/composer/attachment_view.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
  Copyright 2010 Olivier Trichet <nive@nivalis.org>
 
3
 
 
4
  Permission to use, copy, modify, and distribute this software
 
5
  and its documentation for any purpose and without fee is hereby
 
6
  granted, provided that the above copyright notice appear in all
 
7
  copies and that both that the copyright notice and this
 
8
  permission notice and warranty disclaimer appear in supporting
 
9
  documentation, and that the name of the author not be used in
 
10
  advertising or publicity pertaining to distribution of the
 
11
  software without specific, written prior permission.
 
12
 
 
13
  The author disclaim all warranties with regard to this
 
14
  software, including all implied warranties of merchantability
 
15
  and fitness.  In no event shall the author be liable for any
 
16
  special, indirect or consequential damages or any damages
 
17
  whatsoever resulting from loss of use, data or profits, whether
 
18
  in an action of contract, negligence or other tortious action,
 
19
  arising out of or in connection with the use or performance of
 
20
  this software.
 
21
*/
 
22
 
 
23
#include "attachment_view.h"
 
24
 
 
25
#include "../kncomposer.h"
 
26
 
 
27
#include <QHeaderView>
 
28
#include <QKeyEvent>
 
29
 
 
30
 
 
31
namespace KNode {
 
32
namespace Composer {
 
33
 
 
34
// -- AttachmentView ---------------------------------------------------
 
35
 
 
36
AttachmentView::AttachmentView( QWidget *parent )
 
37
  : QTreeWidget( parent )
 
38
{
 
39
  QHeaderView *h = header();
 
40
  h->setMovable( false );
 
41
  h->setResizeMode( QHeaderView::Interactive );
 
42
  h->setStretchLastSection( true );
 
43
}
 
44
 
 
45
AttachmentView::~AttachmentView()
 
46
{
 
47
}
 
48
 
 
49
 
 
50
 
 
51
void AttachmentView::removeCurrentAttachment()
 
52
{
 
53
  QList<QTreeWidgetItem *> items = selectedItems();
 
54
  foreach( QTreeWidgetItem *item, items ) {
 
55
    takeTopLevelItem( indexOfTopLevelItem( item ) );
 
56
 
 
57
    AttachmentViewItem *avi = static_cast< AttachmentViewItem * >( item );
 
58
    bool lastItem = ( topLevelItemCount() == 0 );
 
59
    emit attachmentRemoved( avi->mAttachment, lastItem );
 
60
  }
 
61
  qDeleteAll( items );
 
62
}
 
63
 
 
64
void AttachmentView::editCurrentAttachment()
 
65
{
 
66
  QList<QTreeWidgetItem *> items = selectedItems();
 
67
  if ( items.isEmpty() ) {
 
68
    return;
 
69
  }
 
70
  // Update the view to reflect that we're only editing one item.
 
71
  if ( items.size() > 1 ) {
 
72
    setCurrentItem( items[ 0 ] );
 
73
  }
 
74
 
 
75
  AttachmentViewItem *item = static_cast< AttachmentViewItem * >( currentItem() );
 
76
  QPointer<KNComposer::AttachmentPropertiesDlg> dlg = new KNComposer::AttachmentPropertiesDlg( item->mAttachment, this );
 
77
  if ( dlg->exec() == QDialog::Accepted && dlg ) {
 
78
    item->emitDataChanged(); // notify the changes
 
79
  }
 
80
  delete dlg;
 
81
}
 
82
 
 
83
 
 
84
 
 
85
const QList<KNAttachment::Ptr> AttachmentView::attachments()
 
86
{
 
87
  QList<KNAttachment::Ptr> al;
 
88
  KNAttachment::Ptr a;
 
89
  QTreeWidgetItemIterator it( this, QTreeWidgetItemIterator::All );
 
90
  while ( *it ) {
 
91
    a = static_cast< AttachmentViewItem * >( *it )->mAttachment;
 
92
    al.append( a );
 
93
    ++it;
 
94
  }
 
95
  return al;
 
96
}
 
97
 
 
98
 
 
99
 
 
100
void AttachmentView::keyPressEvent( QKeyEvent *event )
 
101
{
 
102
  if ( !selectedItems().isEmpty() ) {
 
103
    switch ( event->key() ) {
 
104
      case Qt::Key_Delete:
 
105
        emit deletePressed();
 
106
        break;
 
107
      case Qt::Key_Return:
 
108
      case Qt::Key_Enter:
 
109
        emit returnPressed();
 
110
        break;
 
111
    }
 
112
  }
 
113
 
 
114
  QTreeView::keyPressEvent( event );
 
115
}
 
116
 
 
117
void AttachmentView::contextMenuEvent( QContextMenuEvent* event )
 
118
{
 
119
  QTreeWidgetItem *item = itemAt( event->pos() );
 
120
  if ( item ) {
 
121
    setCurrentItem( item );
 
122
    emit contextMenuRequested( event->globalPos() );
 
123
    return;
 
124
  }
 
125
 
 
126
  QAbstractScrollArea::contextMenuEvent( event );
 
127
}
 
128
 
 
129
 
 
130
 
 
131
// -- AttachmentViewItem -----------------------------------------------
 
132
 
 
133
AttachmentViewItem::AttachmentViewItem( AttachmentView *parent, KNAttachment::Ptr attachment )
 
134
  : QTreeWidgetItem( parent ),
 
135
    mAttachment( attachment )
 
136
{
 
137
  Q_ASSERT( mAttachment );
 
138
}
 
139
 
 
140
AttachmentViewItem::~AttachmentViewItem()
 
141
{
 
142
}
 
143
 
 
144
QVariant AttachmentViewItem::data( int column, int role ) const
 
145
{
 
146
  if ( role == Qt::DisplayRole ) {
 
147
    switch ( column ) {
 
148
      case AttachmentView::File:
 
149
        return mAttachment->name();
 
150
      case AttachmentView::Type:
 
151
        return mAttachment->mimeType();
 
152
      case AttachmentView::Size:
 
153
        return mAttachment->contentSize();
 
154
      case AttachmentView::Description:
 
155
        return mAttachment->description();
 
156
      case AttachmentView::Encoding:
 
157
        return mAttachment->encoding();
 
158
    }
 
159
  }
 
160
 
 
161
  return QTreeWidgetItem::data( column, role );
 
162
}
 
163
 
 
164
 
 
165
 
 
166
 
 
167
} // namespace Composer
 
168
} // namespace KNode
 
169
 
 
170
#include "attachment_view.moc"