1/*
2 * Copyright (C) 2009, Martin Robinson
3 *
4 *  This library is free software; you can redistribute it and/or
5 *  modify it under the terms of the GNU Lesser General Public
6 *  License as published by the Free Software Foundation; either
7 *  version 2 of the License, or (at your option) any later version.
8 *
9 *  This library 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 GNU
12 *  Lesser General Public License for more details.
13 *
14 *  You should have received a copy of the GNU Lesser General Public
15 *  License along with this library; if not, write to the Free Software
16 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17 */
18
19#ifndef DataObjectGtk_h
20#define DataObjectGtk_h
21
22#include "FileList.h"
23#include "URL.h"
24#include "Range.h"
25#include <wtf/RefCounted.h>
26#include <wtf/gobject/GRefPtr.h>
27#include <wtf/text/CString.h>
28#include <wtf/text/StringHash.h>
29
30namespace WebCore {
31
32class DataObjectGtk : public RefCounted<DataObjectGtk> {
33public:
34    static PassRefPtr<DataObjectGtk> create()
35    {
36        return adoptRef(new DataObjectGtk());
37    }
38
39    const URL& url() const { return m_url; }
40    const String& uriList() const { return m_uriList; }
41    const Vector<String>& filenames() const { return m_filenames; }
42    GdkPixbuf* image() const { return m_image.get(); }
43    void setRange(PassRefPtr<Range> newRange) { m_range = newRange; }
44    void setImage(GdkPixbuf* newImage) { m_image = newImage; }
45    void setURL(const URL&, const String&);
46    bool hasUnknownTypeData() const { return !m_unknownTypeData.isEmpty(); }
47    bool hasText() const { return m_range || !m_text.isEmpty(); }
48    bool hasMarkup() const { return m_range || !m_markup.isEmpty(); }
49    bool hasURIList() const { return !m_uriList.isEmpty(); }
50    bool hasURL() const { return !m_url.isEmpty() && m_url.isValid(); }
51    bool hasFilenames() const { return !m_filenames.isEmpty(); }
52    bool hasImage() const { return m_image; }
53    void clearURIList() { m_uriList = ""; }
54    void clearURL() { m_url = URL(); }
55    void clearImage() { m_image = 0; }
56
57    String text() const;
58    String markup() const;
59    String unknownTypeData(const String& type) const { return m_unknownTypeData.get(type); }
60    HashMap<String, String> unknownTypes() const;
61    void setText(const String&);
62    void setMarkup(const String&);
63    void setUnknownTypeData(const String& type, const String& data) { m_unknownTypeData.set(type, data); }
64    void setURIList(const String&);
65    String urlLabel() const;
66
67    void clearAllExceptFilenames();
68    void clearAll();
69    void clearText();
70    void clearMarkup();
71
72    static DataObjectGtk* forClipboard(GtkClipboard*);
73
74private:
75    String m_text;
76    String m_markup;
77    URL m_url;
78    String m_uriList;
79    Vector<String> m_filenames;
80    GRefPtr<GdkPixbuf> m_image;
81    RefPtr<Range> m_range;
82    HashMap<String, String> m_unknownTypeData;
83};
84
85}
86
87#endif // DataObjectGtk_h
88