~ubuntu-branches/ubuntu/lucid/kmess/lucid

« back to all changes in this revision

Viewing changes to src/chat/chatview.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mark Purcell
  • Date: 2009-12-05 21:19:26 UTC
  • mfrom: (1.1.7 upstream) (0.1.8 sid)
  • Revision ID: james.westby@ubuntu.com-20091205211926-r26u8j38kysf6o2p
Tags: 2.0.2-1
* New upstream release 
  - Fixes friendly names (LP: #485640)
* Update Homepage: http://kmess.org
* Add Build-Depends: libphonon-dev | libqt4-phonon-dev (ubuntu friendly)
* kmess.1 fix lintian:hyphen-used-as-minus-sign

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
#include "../kmess.h"
28
28
#include "../kmessapplication.h"
29
29
#include "contactswidget.h"
30
 
#include "inkedit.h"
 
30
 
 
31
#include <IsfQt>
 
32
#include <IsfInkCanvas>
31
33
 
32
34
#include <QClipboard>
33
35
#include <QDropEvent>
34
36
#include <QEvent>
35
37
#include <QRegExp>
 
38
#include <QTemporaryFile>
36
39
#include <QTextCodec>
37
40
#include <QTextDocument>
38
41
#include <QTextOption>
57
60
, initialized_( false )
58
61
{
59
62
  // Insert a KHTMLPart in the placeholder
60
 
  chatMessageView_ = new ChatMessageView( this );
 
63
  chatMessageView_ = new ChatMessageView( this, this );
61
64
  connect( chatMessageView_, SIGNAL(                popupMenu(const QString&,const QPoint&)  ),
62
65
           this,             SLOT  (      slotShowContextMenu(const QString&,const QPoint&)  ) );
63
66
  connect( chatMessageView_, SIGNAL(           openUrlRequest(const KUrl&)                   ),
68
71
  // Create a layout to maximize the KHTMLPart
69
72
  QVBoxLayout *layout = new QVBoxLayout( this );
70
73
  layout->setContentsMargins( 0, 6, 0, 0 );
71
 
  layout->addWidget( chatMessageView_->widget() );
 
74
  layout->addWidget( chatMessageView_->view() );
72
75
 
73
76
  // And to the messages view
74
77
  chatMessageView_->view()->setAcceptDrops( true );
75
78
  chatMessageView_->view()->installEventFilter( this );
76
79
 
77
80
  // Create the containers for this chat's current text and drawing
78
 
  inkEditContents_     = new InkImage();
79
81
  messageEditContents_ = new QTextDocument();
 
82
  inkDrawing_          = new Isf::Drawing();
80
83
 
81
84
  // Adapt the new document for RTL is necessary
82
85
  if( QApplication::isRightToLeft() )
95
98
{
96
99
  // Delete the related widgets
97
100
  delete contactsWidget_;
98
 
  delete inkEditContents_;
 
101
  delete inkDrawing_;
99
102
  delete messageEditContents_;
100
103
}
101
104
 
125
128
  switch( event->type() )
126
129
  {
127
130
    case QEvent::DragEnter:
 
131
    case QEvent::DragMove:
128
132
    {
129
133
      QDragEnterEvent *dragEvent = static_cast<QDragEnterEvent*>( event );
130
134
 
131
 
      if( dragEvent->mimeData()->hasUrls() )
132
 
      {
133
 
        dragEvent->acceptProposedAction();
134
 
        return true;
135
 
      }
136
 
      else if( dragEvent->mimeData()->hasFormat( "application/kmess.list.item" ) )
137
 
      {
138
 
        dragEvent->acceptProposedAction();
139
 
        return true;
140
 
      }
141
 
 
 
135
      if( ! dragEvent )
 
136
      {
 
137
#ifdef KMESSDEBUG_CHATVIEW
 
138
          kDebug() << "Ignoring invalid drag event!";
 
139
#endif
 
140
        return false;
 
141
      }
 
142
 
 
143
      const QMimeData *mimeData = dragEvent->mimeData();
 
144
      if( mimeData->hasUrls()
 
145
      ||  mimeData->hasImage()
 
146
      ||  mimeData->hasFormat( "application/kmess.list.item" ) )
 
147
      {
 
148
#ifdef KMESSDEBUG_CHATVIEW
 
149
        kDebug() << "Accepting drag event of mimetypes:" << dragEvent->mimeData()->formats();
 
150
#endif
 
151
        dragEvent->acceptProposedAction();
 
152
        return true;
 
153
      }
 
154
 
 
155
#ifdef KMESSDEBUG_CHATVIEW
 
156
      kDebug() << "Ignoring invalid drop having mimetypes:" << dragEvent->mimeData()->formats();
 
157
#endif
142
158
      break;
143
159
    }
144
160
 
147
163
      QDropEvent *dropEvent = static_cast<QDropEvent*>( event );
148
164
      const QMimeData *data = dropEvent->mimeData();
149
165
 
150
 
      // Process a file transfer drop only if it contains file URLs
151
 
      // and comes from out of our application.
152
 
      if( data->hasUrls() && dropEvent->source() == 0 )
153
 
      {
154
 
#ifdef KMESSDEBUG_CHATVIEW
155
 
        kDebug() << "Drag'n'dropped files:" << dropEvent->mimeData()->urls();
 
166
      // Process the drop only if it comes from out of our application.
 
167
      if( ! dropEvent || dropEvent->source() != 0 )
 
168
      {
 
169
#ifdef KMESSDEBUG_CHATVIEW
 
170
        kDebug() << "Ignoring invalid drop!";
 
171
#endif
 
172
        break;
 
173
      }
 
174
 
 
175
      const QMimeData *mimeData = dropEvent->mimeData();
 
176
      if( mimeData->hasUrls() )
 
177
      {
 
178
#ifdef KMESSDEBUG_CHATVIEW
 
179
        kDebug() << "Drag'n'dropped files:" << mimeData->urls();
156
180
#endif
157
181
 
158
182
        // Send the files to the contact
159
 
        startFileTransfer( dropEvent->mimeData()->urls() );
160
 
 
161
 
        dropEvent->acceptProposedAction();
 
183
        startFileTransfer( mimeData->urls() );
 
184
 
 
185
        dropEvent->acceptProposedAction();
 
186
        return true;
 
187
      }
 
188
 
 
189
      if( mimeData->hasImage() )
 
190
      {
 
191
        QImage image( qvariant_cast<QImage>( mimeData->imageData() ) );
 
192
 
 
193
        if( image.isNull() )
 
194
        {
 
195
#ifdef KMESSDEBUG_CHATVIEW
 
196
          kDebug() << "Drag'n'dropped an invalid image!";
 
197
#endif
 
198
          return true;
 
199
        }
 
200
 
 
201
#ifdef KMESSDEBUG_CHATVIEW
 
202
        kDebug() << "Drag'n'dropped a" << image.size() << "image";
 
203
#endif
 
204
 
 
205
        // Create a temporary file where the image will be stored.
 
206
        // TODO: The file is not destroyed, as it needs to be kept
 
207
        // available until the transfer is completed. Find a way
 
208
        // to remove it when KMess quits or as soon as the transfer
 
209
        // is done.
 
210
        QTemporaryFile file;
 
211
        file.setAutoRemove( false );
 
212
        file.setFileTemplate( QDir::tempPath() + "/kmess.XXXXXX.jpg" );
 
213
 
 
214
        if( ! file.open() )
 
215
        {
 
216
#ifdef KMESSDEBUG_CHATVIEW
 
217
          kDebug() << "Cannot create temporary image file!";
 
218
#endif
 
219
          return true;
 
220
        }
 
221
 
 
222
        dropEvent->acceptProposedAction();
 
223
 
 
224
        // Save the image and get its local URL
 
225
        image.save( &file, "JPG" );
 
226
        file.close();
 
227
        QUrl imageUrl( "file://" + file.fileName() );
 
228
 
 
229
        // Send the image to the contact
 
230
        QList<QUrl> urlList;
 
231
        urlList.append( imageUrl );
 
232
        startFileTransfer( urlList );
 
233
 
162
234
        return true;
163
235
      }
164
236
 
218
290
 
219
291
 
220
292
// Return a pointer to the ink image drawn by the user in this chat
221
 
InkImage *ChatView::getInkEditContents() const
 
293
Isf::Drawing *ChatView::getInkDrawing() const
222
294
{
223
 
  return inkEditContents_;
 
295
  return inkDrawing_;
224
296
}
225
297
 
226
298