Changeset View
Changeset View
Standalone View
Standalone View
krusader/Dialogs/popularurls.cpp
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | |||||
44 | #include "../krslots.h" | 44 | #include "../krslots.h" | ||
45 | #include "../GUI/krtreewidget.h" | 45 | #include "../GUI/krtreewidget.h" | ||
46 | 46 | | |||
47 | #define STARTING_RANK 20 | 47 | #define STARTING_RANK 20 | ||
48 | #define INCREASE 2 | 48 | #define INCREASE 2 | ||
49 | #define DECREASE 1 | 49 | #define DECREASE 1 | ||
50 | 50 | | |||
51 | PopularUrls::PopularUrls(QObject *parent) : QObject(parent), | 51 | PopularUrls::PopularUrls(QObject *parent) : QObject(parent), | ||
52 | head(0), tail(0), count(0) | 52 | head(nullptr), tail(nullptr), count(0) | ||
53 | { | 53 | { | ||
54 | dlg = new PopularUrlsDlg(); | 54 | dlg = new PopularUrlsDlg(); | ||
55 | } | 55 | } | ||
56 | 56 | | |||
57 | PopularUrls::~PopularUrls() | 57 | PopularUrls::~PopularUrls() | ||
58 | { | 58 | { | ||
59 | clearList(); | 59 | clearList(); | ||
60 | delete dlg; | 60 | delete dlg; | ||
61 | } | 61 | } | ||
62 | 62 | | |||
63 | void PopularUrls::clearList() | 63 | void PopularUrls::clearList() | ||
64 | { | 64 | { | ||
65 | if (head) { | 65 | if (head) { | ||
66 | UrlNodeP p = head, tmp; | 66 | UrlNodeP p = head, tmp; | ||
67 | while (p) { | 67 | while (p) { | ||
68 | tmp = p; | 68 | tmp = p; | ||
69 | p = p->next; | 69 | p = p->next; | ||
70 | delete tmp; | 70 | delete tmp; | ||
71 | } | 71 | } | ||
72 | } | 72 | } | ||
73 | ranks.clear(); | 73 | ranks.clear(); | ||
74 | head = tail = 0; | 74 | head = tail = nullptr; | ||
75 | } | 75 | } | ||
76 | 76 | | |||
77 | void PopularUrls::save() | 77 | void PopularUrls::save() | ||
78 | { | 78 | { | ||
79 | KConfigGroup svr(krConfig, "Private"); | 79 | KConfigGroup svr(krConfig, "Private"); | ||
80 | // prepare the string list containing urls and int list with ranks | 80 | // prepare the string list containing urls and int list with ranks | ||
81 | QStringList urlList; | 81 | QStringList urlList; | ||
82 | QList<int> rankList; | 82 | QList<int> rankList; | ||
Show All 17 Lines | 98 | if (urlList.count() != rankList.count()) { | |||
100 | return; | 100 | return; | ||
101 | } | 101 | } | ||
102 | clearList(); | 102 | clearList(); | ||
103 | count = 0; | 103 | count = 0; | ||
104 | // iterate through both lists and | 104 | // iterate through both lists and | ||
105 | QStringList::Iterator uit; | 105 | QStringList::Iterator uit; | ||
106 | QList<int>::Iterator rit; | 106 | QList<int>::Iterator rit; | ||
107 | for (uit = urlList.begin(), rit = rankList.begin(); uit != urlList.end() && rit != rankList.end(); ++uit, ++rit) { | 107 | for (uit = urlList.begin(), rit = rankList.begin(); uit != urlList.end() && rit != rankList.end(); ++uit, ++rit) { | ||
108 | UrlNodeP node = new UrlNode; | 108 | auto node = new UrlNode; | ||
109 | node->url = QUrl(*uit); | 109 | node->url = QUrl(*uit); | ||
110 | node->rank = *rit; | 110 | node->rank = *rit; | ||
111 | appendNode(node); | 111 | appendNode(node); | ||
112 | ranks.insert(*uit, node); | 112 | ranks.insert(*uit, node); | ||
113 | } | 113 | } | ||
114 | } | 114 | } | ||
115 | 115 | | |||
116 | 116 | | |||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Line(s) | 210 | { | |||
218 | } | 218 | } | ||
219 | --count; | 219 | --count; | ||
220 | } | 220 | } | ||
221 | 221 | | |||
222 | void PopularUrls::insertNode(UrlNodeP node, UrlNodeP after) | 222 | void PopularUrls::insertNode(UrlNodeP node, UrlNodeP after) | ||
223 | { | 223 | { | ||
224 | if (!after) { // make node head | 224 | if (!after) { // make node head | ||
225 | node->next = head; | 225 | node->next = head; | ||
226 | node->prev = 0; | 226 | node->prev = nullptr; | ||
227 | head->prev = node; | 227 | head->prev = node; | ||
228 | head = node; | 228 | head = node; | ||
229 | } else { | 229 | } else { | ||
230 | if (tail == after) tail = node; | 230 | if (tail == after) tail = node; | ||
231 | node->prev = after; | 231 | node->prev = after; | ||
232 | node->next = after->next; | 232 | node->next = after->next; | ||
233 | if (node->next) { | 233 | if (node->next) { | ||
234 | after->next->prev = node; | 234 | after->next->prev = node; | ||
235 | after->next = node; | 235 | after->next = node; | ||
236 | } | 236 | } | ||
237 | } | 237 | } | ||
238 | ++count; | 238 | ++count; | ||
239 | } | 239 | } | ||
240 | 240 | | |||
241 | // appends 'node' to the end of the list, collecting garbage if needed | 241 | // appends 'node' to the end of the list, collecting garbage if needed | ||
242 | void PopularUrls::appendNode(UrlNodeP node) | 242 | void PopularUrls::appendNode(UrlNodeP node) | ||
243 | { | 243 | { | ||
244 | if (!tail) { // creating the first element | 244 | if (!tail) { // creating the first element | ||
245 | head = tail = node; | 245 | head = tail = node; | ||
246 | node->prev = node->next = 0; | 246 | node->prev = node->next = nullptr; | ||
247 | } else { | 247 | } else { | ||
248 | node->next = 0; | 248 | node->next = nullptr; | ||
249 | node->prev = tail; | 249 | node->prev = tail; | ||
250 | tail->next = node; | 250 | tail->next = node; | ||
251 | tail = node; | 251 | tail = node; | ||
252 | } | 252 | } | ||
253 | ++count; | 253 | ++count; | ||
254 | } | 254 | } | ||
255 | 255 | | |||
256 | void PopularUrls::dumpList() | 256 | void PopularUrls::dumpList() | ||
Show All 18 Lines | |||||
275 | 275 | | |||
276 | // ===================================== PopularUrlsDlg ====================================== | 276 | // ===================================== PopularUrlsDlg ====================================== | ||
277 | PopularUrlsDlg::PopularUrlsDlg(): | 277 | PopularUrlsDlg::PopularUrlsDlg(): | ||
278 | QDialog(krMainWindow) | 278 | QDialog(krMainWindow) | ||
279 | { | 279 | { | ||
280 | setWindowTitle(i18n("Popular URLs")); | 280 | setWindowTitle(i18n("Popular URLs")); | ||
281 | setWindowModality(Qt::WindowModal); | 281 | setWindowModality(Qt::WindowModal); | ||
282 | 282 | | |||
283 | QVBoxLayout *mainLayout = new QVBoxLayout; | 283 | auto *mainLayout = new QVBoxLayout; | ||
284 | setLayout(mainLayout); | 284 | setLayout(mainLayout); | ||
285 | 285 | | |||
286 | QGridLayout *layout = new QGridLayout; | 286 | auto *layout = new QGridLayout; | ||
287 | layout->setContentsMargins(0, 0, 0, 0); | 287 | layout->setContentsMargins(0, 0, 0, 0); | ||
288 | 288 | | |||
289 | // listview to contain the urls | 289 | // listview to contain the urls | ||
290 | urls = new KrTreeWidget(this); | 290 | urls = new KrTreeWidget(this); | ||
291 | urls->header()->hide(); | 291 | urls->header()->hide(); | ||
292 | urls->setSortingEnabled(false); | 292 | urls->setSortingEnabled(false); | ||
293 | urls->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); | 293 | urls->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); | ||
294 | 294 | | |||
Show All 30 Lines | |||||
325 | void PopularUrlsDlg::slotVisibilityChanged() | 325 | void PopularUrlsDlg::slotVisibilityChanged() | ||
326 | { | 326 | { | ||
327 | // select the first visible item | 327 | // select the first visible item | ||
328 | QList<QTreeWidgetItem *> list = urls->selectedItems(); | 328 | QList<QTreeWidgetItem *> list = urls->selectedItems(); | ||
329 | if (list.count() > 0 && !list[0]->isHidden()) | 329 | if (list.count() > 0 && !list[0]->isHidden()) | ||
330 | return; | 330 | return; | ||
331 | 331 | | |||
332 | urls->clearSelection(); | 332 | urls->clearSelection(); | ||
333 | urls->setCurrentItem(0); | 333 | urls->setCurrentItem(nullptr); | ||
334 | 334 | | |||
335 | QTreeWidgetItemIterator it(urls); | 335 | QTreeWidgetItemIterator it(urls); | ||
336 | while (*it) { | 336 | while (*it) { | ||
337 | if (!(*it)->isHidden()) { | 337 | if (!(*it)->isHidden()) { | ||
338 | (*it)->setSelected(true); | 338 | (*it)->setSelected(true); | ||
339 | urls->setCurrentItem(*it); | 339 | urls->setCurrentItem(*it); | ||
340 | break; | 340 | break; | ||
341 | } | 341 | } | ||
342 | it++; | 342 | it++; | ||
343 | } | 343 | } | ||
344 | } | 344 | } | ||
345 | 345 | | |||
346 | PopularUrlsDlg::~PopularUrlsDlg() | 346 | PopularUrlsDlg::~PopularUrlsDlg() | ||
347 | { | 347 | { | ||
348 | delete search; | 348 | delete search; | ||
349 | delete urls; | 349 | delete urls; | ||
350 | } | 350 | } | ||
351 | 351 | | |||
352 | void PopularUrlsDlg::run(QList<QUrl> list) | 352 | void PopularUrlsDlg::run(QList<QUrl> list) | ||
353 | { | 353 | { | ||
354 | // populate the listview | 354 | // populate the listview | ||
355 | urls->clear(); | 355 | urls->clear(); | ||
356 | QList<QUrl>::Iterator it; | 356 | QList<QUrl>::Iterator it; | ||
357 | 357 | | |||
358 | QTreeWidgetItem * lastItem = 0; | 358 | QTreeWidgetItem * lastItem = nullptr; | ||
359 | 359 | | |||
360 | for (it = list.begin(); it != list.end(); ++it) { | 360 | for (it = list.begin(); it != list.end(); ++it) { | ||
361 | QTreeWidgetItem *item = new QTreeWidgetItem(urls, lastItem); | 361 | auto *item = new QTreeWidgetItem(urls, lastItem); | ||
362 | lastItem = item; | 362 | lastItem = item; | ||
363 | item->setText(0, (*it).isLocalFile() ? (*it).path() : (*it).toDisplayString()); | 363 | item->setText(0, (*it).isLocalFile() ? (*it).path() : (*it).toDisplayString()); | ||
364 | item->setIcon(0, (*it).isLocalFile() ? Icon("folder") : Icon("folder-html")); | 364 | item->setIcon(0, (*it).isLocalFile() ? Icon("folder") : Icon("folder-html")); | ||
365 | } | 365 | } | ||
366 | 366 | | |||
367 | setMinimumSize(urls->sizeHint().width() + 45, 400); | 367 | setMinimumSize(urls->sizeHint().width() + 45, 400); | ||
368 | 368 | | |||
369 | search->clear(); | 369 | search->clear(); | ||
370 | search->setFocus(); | 370 | search->setFocus(); | ||
371 | selection = -1; | 371 | selection = -1; | ||
372 | slotVisibilityChanged(); | 372 | slotVisibilityChanged(); | ||
373 | exec(); | 373 | exec(); | ||
374 | } | 374 | } | ||
375 | 375 | |