~ubuntu-branches/ubuntu/gutsy/kdebase-workspace/gutsy

« back to all changes in this revision

Viewing changes to klipper/historyitem.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-09-05 20:45:14 UTC
  • Revision ID: james.westby@ubuntu.com-20070905204514-632hhspl0nvrc84i
Tags: upstream-3.93.0
ImportĀ upstreamĀ versionĀ 3.93.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8; -*-
 
2
/* This file is part of the KDE project
 
3
   Copyright (C) 2004  Esben Mose Hansen <kde@mosehansen.dk>
 
4
 
 
5
   This program is free software; you can redistribute it and/or
 
6
   modify it under the terms of the GNU General Public
 
7
   License as published by the Free Software Foundation; either
 
8
   version 2 of the License, or (at your option) any later version.
 
9
 
 
10
   This program is distributed in the hope that it will be useful,
 
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
    General Public License for more details.
 
14
 
 
15
   You should have received a copy of the GNU General Public License
 
16
   along with this program; see the file COPYING.  If not, write to
 
17
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
18
   Boston, MA 02110-1301, USA.
 
19
*/
 
20
#include <QtGui/QMacMime>
 
21
#include <Qt3Support/Q3ColorDrag>
 
22
#include <QMap>
 
23
 
 
24
#include <QPixmap>
 
25
 
 
26
#include <kdebug.h>
 
27
#include <k3urldrag.h>
 
28
 
 
29
#include "historyitem.h"
 
30
#include "historystringitem.h"
 
31
#include "historyimageitem.h"
 
32
#include "historyurlitem.h"
 
33
 
 
34
HistoryItem::HistoryItem() {
 
35
 
 
36
}
 
37
 
 
38
HistoryItem::~HistoryItem() {
 
39
 
 
40
}
 
41
 
 
42
HistoryItem* HistoryItem::create( const QMimeData* data )
 
43
{
 
44
#if 0
 
45
    int i=0;
 
46
    while ( const char* f = aSource.format( i++ ) ) {
 
47
        kDebug() << "format(" << i <<"): " << f;
 
48
    }
 
49
#endif
 
50
    if (KUrl::List::canDecode(data))
 
51
    {
 
52
        KUrl::MetaDataMap metaData;
 
53
        KUrl::List urls = KUrl::List::fromMimeData(data, &metaData);
 
54
        QByteArray a = data->data("application/x-kde-cutselection");
 
55
        bool cut = !a.isEmpty() && (a.at(0) == '1'); // true if 1
 
56
        return new HistoryURLItem(urls, metaData, cut);
 
57
    }
 
58
    if (data->hasText())
 
59
    {
 
60
        return new HistoryStringItem(data->text());
 
61
    }
 
62
    if (data->hasImage())
 
63
    {
 
64
        QImage image = qvariant_cast<QImage>(data->imageData());
 
65
        return new HistoryImageItem(QPixmap::fromImage(image));
 
66
    }
 
67
 
 
68
    return 0; // Failed.
 
69
}
 
70
 
 
71
HistoryItem* HistoryItem::create( QDataStream& aSource ) {
 
72
    if ( aSource.atEnd() ) {
 
73
        return 0;
 
74
    }
 
75
    QString type;
 
76
    aSource >> type;
 
77
    if ( type == "url" ) {
 
78
        KUrl::List urls;
 
79
        QMap< QString, QString > metaData;
 
80
        int cut;
 
81
        aSource >> urls;
 
82
        aSource >> metaData;
 
83
        aSource >> cut;
 
84
        return new HistoryURLItem( urls, metaData, cut );
 
85
    }
 
86
    if ( type == "string" ) {
 
87
        QString text;
 
88
        aSource >> text;
 
89
        return new HistoryStringItem( text );
 
90
    }
 
91
    if ( type == "image" ) {
 
92
        QPixmap image;
 
93
        aSource >> image;
 
94
        return new HistoryImageItem( image );
 
95
    }
 
96
    kWarning() << "Failed to restore history item: Unknown type \"" << type << "\"" ;
 
97
    return 0;
 
98
}
 
99