summaryrefslogtreecommitdiffstats
path: root/konqueror/keditbookmarks/listview.h
blob: 7ffe76c37bb3b10b2b7597958561603257494df7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
// kate: space-indent on; indent-width 3; replace-tabs on;
/* This file is part of the KDE project
   Copyright (C) 2002-2003 Alexander Kellett <lypanov@kde.org>

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
   License version 2 as published by the Free Software Foundation.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef __listview_h
#define __listview_h

#include <assert.h>

#include <tqlistview.h>
#include <tqmap.h>
#include <tqvaluevector.h>

#include <klocale.h>
#include <kbookmark.h>
#include <klistview.h>
#include <kiconloader.h>

#include "toplevel.h"

class TQSplitter;
class KListViewSearchLine;

class KEBListViewItem : public TQListViewItem
{
public:
   KEBListViewItem(TQListView *, const KBookmarkGroup &);
   KEBListViewItem(KEBListViewItem *, TQListViewItem *);
   KEBListViewItem(KEBListViewItem *, TQListViewItem *, const KBookmarkGroup &);
   KEBListViewItem(KEBListViewItem *, const KBookmark &);
   KEBListViewItem(KEBListViewItem *, TQListViewItem *, const KBookmark &);

   KEBListViewItem(TQListView *, const KBookmark &);
   KEBListViewItem(TQListView *, TQListViewItem *, const KBookmark &);

   void nsPut(const TQString &nm);

   void modUpdate();

   void setOldStatus(const TQString &);
   void setTmpStatus(const TQString &);
   void restoreStatus();

   void paintCell(TQPainter *p, const TQColorGroup &cg, int column, int width, int alignment);
   void setSelected ( bool s );

   virtual void setOpen(bool);

   bool isEmptyFolderPadder() const { return m_emptyFolderPadder; }
   const KBookmark bookmark() const { return m_bookmark; }

  typedef enum { GreyStyle, BoldStyle, GreyBoldStyle, DefaultStyle } PaintStyle;

   static bool parentSelected(TQListViewItem * item);

private:
   const TQString nsGet() const;
   void normalConstruct(const KBookmark &);

   KBookmark m_bookmark;
   PaintStyle m_paintStyle;
   bool m_emptyFolderPadder;
   TQString m_oldStatus;
   void greyStyle(TQColorGroup &);
   void boldStyle(TQPainter *);
};

class KEBListView : public KListView
{
   Q_OBJECT
public:
   enum { 
      NameColumn = 0,
      UrlColumn = 1,
      CommentColumn = 2,
      StatusColumn = 3,
      AddressColumn = 4
   };
   KEBListView(TQWidget *parent, bool folderList) 
      : KListView(parent), m_folderList(folderList) {}
   virtual ~KEBListView() {}

   void init();
   void makeConnections();
   void readonlyFlagInit(bool);

   void loadColumnSetting();
   void saveColumnSetting();

   void updateByURL(TQString url);

   bool isFolderList() const { return m_folderList; }

   KEBListViewItem* rootItem() const;

public slots:
   virtual void rename(TQListViewItem *item, int c);
   void slotMoved();
   void slotContextMenu(KListView *, TQListViewItem *, const TQPoint &);
   void slotItemRenamed(TQListViewItem *, const TQString &, int);
   void slotDoubleClicked(TQListViewItem *, const TQPoint &, int);
   void slotDropped(TQDropEvent*, TQListViewItem*, TQListViewItem*);
   void slotColumnSizeChanged(int, int, int);

protected:
   virtual bool acceptDrag(TQDropEvent *e) const;
   virtual TQDragObject* dragObject();

private:
   bool m_folderList;
   bool m_widthsDirty;
};

// DESIGN - make some stuff private if possible
class ListView : public TQObject
{
   Q_OBJECT
public:
   // init stuff
   void initListViews();
   void updateListViewSetup(bool readOnly);
   void connectSignals();
   void setSearchLine(KListViewSearchLine * searchline) { m_searchline = searchline; };

   // selected item stuff
   void selected(KEBListViewItem * item, bool s);
   
   void invalidate(const TQString & address);
   void invalidate(TQListViewItem * item);
   void fixUpCurrent(const TQString & address);

   KEBListViewItem * firstSelected() const;
   TQValueVector<KEBListViewItem *> selectedItemsMap() const;

   TQValueList<TQString> selectedAddresses();

   // bookmark helpers
   TQValueList<KBookmark> itemsToBookmarks(const TQValueVector<KEBListViewItem *> & items) const;

   // bookmark stuff
   TQValueList<KBookmark> allBookmarks() const;
   TQValueList<KBookmark> selectedBookmarksExpanded() const;

   // address stuff
   KEBListViewItem* getItemAtAddress(const TQString &address) const;
   TQString userAddress() const;

   // gui stuff - DESIGN - all of it???
   SelcAbilities getSelectionAbilities() const;

   void updateListView();
   void setOpen(bool open); // DESIGN -rename to setAllOpenFlag
   void setCurrent(KEBListViewItem *item, bool select);
   void renameNextCell(bool dir);

   TQWidget *widget() const { return m_listView; }
   void rename(int);
   void clearSelection();

   void updateStatus(TQString url);

   static ListView* self() { return s_self; }
   static void createListViews(TQSplitter *parent);

   void handleMoved(KEBListView *);
   void handleDropped(KEBListView *, TQDropEvent *, TQListViewItem *, TQListViewItem *);
   void handleContextMenu(KEBListView *, KListView *, TQListViewItem *, const TQPoint &);
   void handleDoubleClicked(KEBListView *, TQListViewItem *, const TQPoint &, int);
   void handleItemRenamed(KEBListView *, TQListViewItem *, const TQString &, int);

   static void startRename(int column, KEBListViewItem *item);

   static void deselectAllChildren(KEBListViewItem *item);

   ~ListView();

public slots:
   void slotBkInfoUpdateListViewItem();

private:
   void updateTree();
   void selectedBookmarksExpandedHelper(KEBListViewItem * item, TQValueList<KBookmark> & bookmarks) const;
   void fillWithGroup(KEBListView *, KBookmarkGroup, KEBListViewItem * = 0);

   ListView();

   KEBListView *m_listView;
   KListViewSearchLine * m_searchline;

//  Actually this is a std:set, the bool is ignored
   TQMap<KEBListViewItem *, bool> mSelectedItems;
   bool m_needToFixUp;

   // statics
   static ListView *s_self;
   static int s_myrenamecolumn;
   static KEBListViewItem *s_myrenameitem;
   static TQStringList s_selected_addresses;
   static TQString s_current_address;
};

#endif