12
|
1 |
/*
|
|
2 |
* bookmarkscontroller.cpp
|
|
3 |
*
|
|
4 |
* Created on: Aug 25, 2010
|
|
5 |
* Author: mmoretti
|
|
6 |
*/
|
|
7 |
|
|
8 |
|
|
9 |
#include <QObject>
|
|
10 |
#include <QWidget>
|
|
11 |
#include <QDebug>
|
|
12 |
|
|
13 |
#include "bookmarkscontroller.h"
|
|
14 |
#include "BookmarksManager.h"
|
|
15 |
#include "BookmarkFav.h"
|
|
16 |
#include "BookmarkResults.h"
|
14
|
17 |
#include "HistoryManager.h"
|
12
|
18 |
|
|
19 |
BookmarksController::BookmarksController(QWidget *parent) :
|
|
20 |
QObject(parent)
|
|
21 |
{
|
|
22 |
setObjectName("bookmarksController");
|
|
23 |
m_bm = new BookmarksManager(parent);
|
|
24 |
}
|
|
25 |
|
|
26 |
BookmarksController::~BookmarksController() {
|
|
27 |
// TODO Auto-generated destructor stub
|
|
28 |
}
|
|
29 |
|
|
30 |
BookmarksController* BookmarksController::getSingleton()
|
|
31 |
{
|
|
32 |
static BookmarksController* singleton = 0;
|
|
33 |
|
|
34 |
if(!singleton){
|
|
35 |
singleton = new BookmarksController;
|
|
36 |
}
|
|
37 |
|
|
38 |
//assert(singleton);
|
|
39 |
return singleton;
|
|
40 |
}
|
|
41 |
|
|
42 |
|
|
43 |
int BookmarksController::addBookmark(QString title, QString URL)
|
|
44 |
{
|
|
45 |
int bmid = m_bm->addBookmark(title, URL);
|
|
46 |
// qDebug() << __PRETTY_FUNCTION__ << "added bookmark" << title << URL << bmid << "emitting bookmarkAdded";
|
|
47 |
emit bookmarkAdded(title, URL, bmid);
|
|
48 |
return(bmid);
|
|
49 |
}
|
|
50 |
|
|
51 |
int BookmarksController::modifyBookmark(int origBookmarkId, QString newTitle, QString newURL)
|
|
52 |
{
|
|
53 |
int retstat = m_bm->modifyBookmark(origBookmarkId, newTitle, newURL);
|
|
54 |
emit bookmarkModified(newTitle, newURL, origBookmarkId);
|
|
55 |
return retstat;
|
|
56 |
}
|
|
57 |
|
|
58 |
int BookmarksController::deleteBookmark(int bookmarkId)
|
|
59 |
{
|
|
60 |
return m_bm->deleteBookmark(bookmarkId);
|
|
61 |
}
|
|
62 |
|
|
63 |
int BookmarksController::clearAll()
|
|
64 |
{
|
|
65 |
int retstat = m_bm->clearAll();
|
|
66 |
emit bookmarksCleared();
|
|
67 |
return retstat;
|
|
68 |
}
|
|
69 |
|
|
70 |
int BookmarksController::findAllBookmarks()
|
|
71 |
{
|
|
72 |
m_bmr = m_bm->findAllBookmarks();
|
|
73 |
if (!m_bmr)
|
|
74 |
return -1;
|
|
75 |
return(0);
|
|
76 |
}
|
|
77 |
|
|
78 |
// This is only necessary because JS can't handle null objects being returned by nextBookmark
|
|
79 |
bool BookmarksController::hasMoreBookmarks()
|
|
80 |
{
|
|
81 |
if (!m_bmr)
|
|
82 |
return false;
|
|
83 |
|
|
84 |
m_bmf = m_bmr->nextBookmark();
|
|
85 |
if (!m_bmf) {
|
|
86 |
delete m_bmr;
|
|
87 |
m_bmr = 0;
|
|
88 |
return false;
|
|
89 |
}
|
|
90 |
|
|
91 |
return true;
|
|
92 |
}
|
|
93 |
|
|
94 |
|
|
95 |
QObject *BookmarksController::nextBookmark()
|
|
96 |
{
|
|
97 |
return m_bmf;
|
|
98 |
}
|
|
99 |
|
|
100 |
int BookmarksController::reorderBookmark(int bookmarkID, int newIndex)
|
|
101 |
{
|
|
102 |
return m_bm->reorderBookmark(bookmarkID, newIndex);
|
|
103 |
}
|
|
104 |
|
|
105 |
QObject *BookmarksController::findBookmark(int bookmarkID)
|
|
106 |
{
|
|
107 |
return m_bm->findBookmark(bookmarkID);
|
|
108 |
}
|
|
109 |
|
|
110 |
void BookmarksController::showBookmarkEditDialog(QString title, QString url, int bookmarkID)
|
|
111 |
{
|
|
112 |
// This is SOOOO convoluted; in our js, in order to call a function in another scope, we have to call a function here that emits a signal that is connected to that function, wtf?
|
|
113 |
emit launchBookmarkEditDailog(title, url, bookmarkID);
|
|
114 |
}
|
|
115 |
|
14
|
116 |
QObjectList BookmarksController::suggestSimilar(QString suggest)
|
|
117 |
{
|
|
118 |
QMap<QString, QString> bookmarksMap = m_bm->findBookmarks(suggest);
|
|
119 |
QMap<QString, QString> historyMap = WRT::HistoryManager::getSingleton()->findHistory(suggest);
|
|
120 |
// Now combine the result
|
|
121 |
QObjectList suggestions;
|
|
122 |
|
|
123 |
QMapIterator<QString,QString> bhi(historyMap);
|
|
124 |
while (bhi.hasNext()) {
|
|
125 |
bhi.next();
|
|
126 |
suggestions.append(new Suggestion(bhi.key(), bhi.value()));
|
|
127 |
}
|
|
128 |
|
|
129 |
QMapIterator<QString,QString> bmi(bookmarksMap);
|
|
130 |
while (bmi.hasNext()) {
|
|
131 |
bmi.next();
|
|
132 |
if (historyMap.contains(bmi.key()))
|
|
133 |
continue;
|
|
134 |
suggestions.append(new Suggestion(bmi.key(), bmi.value()));
|
|
135 |
}
|
|
136 |
|
|
137 |
return suggestions;
|
|
138 |
|
|
139 |
}
|
|
140 |
|
12
|
141 |
// TODO add tag stuff when we get a ui for it
|