add more spacing
[personal-kdebase.git] / apps / konsole / src / ViewProperties.h
blob20538ef18bcb35a95a7f28c8f79435af7c06137a
1 /*
2 Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program 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
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301 USA.
20 #ifndef VIEWPROPERTIES_H
21 #define VIEWPROPERTIES_H
23 // Qt
24 #include <QtGui/QIcon>
25 #include <QtCore/QObject>
26 #include <QtCore/QHash>
27 #include <QtCore/QMimeData>
29 // KDE
30 #include <KUrl>
32 namespace Konsole
35 /**
36 * Encapsulates user-visible information about the terminal session currently being displayed in a view,
37 * such as the associated title and icon.
39 * This can be used by navigation widgets in a ViewContainer sub-class to provide a tab, label or other
40 * item for switching between views.
42 class ViewProperties : public QObject
44 Q_OBJECT
46 public:
47 ViewProperties(QObject* parent);
48 virtual ~ViewProperties();
50 /** Returns the icon associated with a view */
51 QIcon icon() const;
52 /** Returns the title associated with a view */
53 QString title() const;
55 /**
56 * Returns the URL current associated with a view.
57 * The default implementation returns an empty URL.
59 virtual KUrl url() const;
61 /**
62 * Returns the current directory associated with a view.
63 * This may be the same as url()
64 * The default implementation returns an empty string.
66 virtual QString currentDir() const;
68 /**
69 * A unique identifier associated with this
70 * ViewProperties instance.
72 int identifier() const;
74 /**
75 * Sub-classes may re-implement this method to display a message to the user
76 * to allow them to confirm whether to close a view.
77 * The default implementation always returns true
79 virtual bool confirmClose() const
80 { return true; }
82 /** Finds a ViewProperties instance given its numeric identifier. */
83 static ViewProperties* propertiesById(int id);
85 /** Name of mime format to use in drag-and-drop operations. */
86 static QString mimeType()
87 { return _mimeType; }
89 /** Returns a new QMimeData instance which represents the view with the given @p id
90 * (See identifier()). The QMimeData instance returned must be deleted by the caller.
92 static QMimeData* createMimeData(int id)
94 QMimeData* mimeData = new QMimeData;
95 QByteArray data((char*)&id,sizeof(int));
96 mimeData->setData(mimeType(),data);
97 return mimeData;
99 /** Decodes a QMimeData instance created with createMimeData() and returns the identifier
100 * of the associated view. The associated ViewProperties instance can then be retrieved by
101 * calling propertiesById()
103 * The QMimeData instance must support the mime format returned by mimeType()
105 static int decodeMimeData(const QMimeData* mimeData)
107 return *(int*)(mimeData->data(ViewProperties::mimeType()).constData());
110 signals:
111 /** Emitted when the icon for a view changes */
112 void iconChanged(ViewProperties* properties);
113 /** Emitted when the title for a view changes */
114 void titleChanged(ViewProperties* properties);
115 /** Emitted when activity has occurred in this view. */
116 void activity(ViewProperties* item);
118 public slots:
120 * Requests the renaming of this view.
121 * The default implementation does nothing.
123 virtual void rename();
125 protected slots:
126 /** Emits the activity() signal. */
127 void fireActivity();
129 protected:
130 /**
131 * Subclasses may call this method to change the title. This causes
132 * a titleChanged() signal to be emitted
134 void setTitle(const QString& title);
136 * Subclasses may call this method to change the icon. This causes
137 * an iconChanged() signal to be emitted
139 void setIcon(const QIcon& icon);
140 /** Subclasses may call this method to change the identifier. */
141 void setIdentifier(int id);
142 private:
143 QIcon _icon;
144 QString _title;
145 int _id;
147 static QHash<int,ViewProperties*> _viewProperties;
148 static QString _mimeType;
153 #endif //VIEWPROPERTIES_H