summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-04-14 20:11:54 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-04-14 20:11:54 (GMT)
commit900e23128a16bd49d8929a232ac57fc7e30ad3f9 (patch)
treea5d04c86dc0ac5efb887579699e86143f12f20a8 /src
parent4c6be4ff2cc822d9c1ed36c9c88261771775dc02 (diff)
downloadpowder-900e23128a16bd49d8929a232ac57fc7e30ad3f9.zip
powder-900e23128a16bd49d8929a232ac57fc7e30ad3f9.tar.gz
Add ability to get favourites
Diffstat (limited to 'src')
-rw-r--r--src/client/Client.cpp24
-rw-r--r--src/client/Client.h2
-rw-r--r--src/options/OptionsController.cpp18
-rw-r--r--src/options/OptionsController.h17
-rw-r--r--src/options/OptionsModel.cpp18
-rw-r--r--src/options/OptionsModel.h17
-rw-r--r--src/options/OptionsView.cpp19
-rw-r--r--src/options/OptionsView.h19
-rw-r--r--src/search/SearchController.cpp17
-rw-r--r--src/search/SearchController.h1
-rw-r--r--src/search/SearchModel.cpp17
-rw-r--r--src/search/SearchModel.h8
-rw-r--r--src/search/SearchView.cpp50
-rw-r--r--src/search/SearchView.h2
14 files changed, 213 insertions, 16 deletions
diff --git a/src/client/Client.cpp b/src/client/Client.cpp
index 2d65677..9e4732b 100644
--- a/src/client/Client.cpp
+++ b/src/client/Client.cpp
@@ -840,7 +840,7 @@ std::vector<Comment*> * Client::GetComments(int saveID, int start, int count)
return commentArray;
}
-std::vector<Save*> * Client::SearchSaves(int start, int count, string query, string sort, bool showOwn, int & resultCount)
+std::vector<Save*> * Client::SearchSaves(int start, int count, string query, string sort, std::string category, int & resultCount)
{
lastError = "";
resultCount = 0;
@@ -860,15 +860,21 @@ std::vector<Save*> * Client::SearchSaves(int start, int count, string query, str
urlStream << URLEscape(" ");
urlStream << URLEscape("sort:") << URLEscape(sort);
}
- if(showOwn && authUser.ID)
- {
- if(query.length())
- urlStream << URLEscape(" ");
- urlStream << URLEscape("user:") << URLEscape(authUser.Username);
- }
-
}
- data = http_simple_get((char *)urlStream.str().c_str(), &dataStatus, &dataLength);
+ if(category.length())
+ {
+ urlStream << "&Category=" << URLEscape(category);
+ }
+ if(authUser.ID)
+ {
+ std::stringstream userIDStream;
+ userIDStream << authUser.ID;
+ data = http_auth_get((char *)urlStream.str().c_str(), (char *)(userIDStream.str().c_str()), NULL, (char *)(authUser.SessionID.c_str()), &dataStatus, &dataLength);
+ }
+ else
+ {
+ data = http_simple_get((char *)urlStream.str().c_str(), &dataStatus, &dataLength);
+ }
if(dataStatus == 200 && data)
{
try
diff --git a/src/client/Client.h b/src/client/Client.h
index 2867f53..ff571f8 100644
--- a/src/client/Client.h
+++ b/src/client/Client.h
@@ -62,7 +62,7 @@ public:
unsigned char * GetSaveData(int saveID, int saveDate, int & dataLength);
LoginStatus Login(string username, string password, User & user);
void ClearThumbnailRequests();
- std::vector<Save*> * SearchSaves(int start, int count, string query, string sort, bool showOwn, int & resultCount);
+ std::vector<Save*> * SearchSaves(int start, int count, string query, string sort, string category, int & resultCount);
std::vector<Comment*> * GetComments(int saveID, int start, int count);
Thumbnail * GetPreview(int saveID, int saveDate);
Thumbnail * GetThumbnail(int saveID, int saveDate);
diff --git a/src/options/OptionsController.cpp b/src/options/OptionsController.cpp
new file mode 100644
index 0000000..ca9a332
--- /dev/null
+++ b/src/options/OptionsController.cpp
@@ -0,0 +1,18 @@
+/*
+ * OptionsController.cpp
+ *
+ * Created on: Apr 14, 2012
+ * Author: Simon
+ */
+
+#include "OptionsController.h"
+
+OptionsController::OptionsController() {
+ // TODO Auto-generated constructor stub
+
+}
+
+OptionsController::~OptionsController() {
+ // TODO Auto-generated destructor stub
+}
+
diff --git a/src/options/OptionsController.h b/src/options/OptionsController.h
new file mode 100644
index 0000000..6621f2f
--- /dev/null
+++ b/src/options/OptionsController.h
@@ -0,0 +1,17 @@
+/*
+ * OptionsController.h
+ *
+ * Created on: Apr 14, 2012
+ * Author: Simon
+ */
+
+#ifndef OPTIONSCONTROLLER_H_
+#define OPTIONSCONTROLLER_H_
+
+class OptionsController {
+public:
+ OptionsController();
+ virtual ~OptionsController();
+};
+
+#endif /* OPTIONSCONTROLLER_H_ */
diff --git a/src/options/OptionsModel.cpp b/src/options/OptionsModel.cpp
new file mode 100644
index 0000000..9aed1cc
--- /dev/null
+++ b/src/options/OptionsModel.cpp
@@ -0,0 +1,18 @@
+/*
+ * OptionsModel.cpp
+ *
+ * Created on: Apr 14, 2012
+ * Author: Simon
+ */
+
+#include "OptionsModel.h"
+
+OptionsModel::OptionsModel() {
+ // TODO Auto-generated constructor stub
+
+}
+
+OptionsModel::~OptionsModel() {
+ // TODO Auto-generated destructor stub
+}
+
diff --git a/src/options/OptionsModel.h b/src/options/OptionsModel.h
new file mode 100644
index 0000000..f04d071
--- /dev/null
+++ b/src/options/OptionsModel.h
@@ -0,0 +1,17 @@
+/*
+ * OptionsModel.h
+ *
+ * Created on: Apr 14, 2012
+ * Author: Simon
+ */
+
+#ifndef OPTIONSMODEL_H_
+#define OPTIONSMODEL_H_
+
+class OptionsModel {
+public:
+ OptionsModel();
+ virtual ~OptionsModel();
+};
+
+#endif /* OPTIONSMODEL_H_ */
diff --git a/src/options/OptionsView.cpp b/src/options/OptionsView.cpp
new file mode 100644
index 0000000..1c79961
--- /dev/null
+++ b/src/options/OptionsView.cpp
@@ -0,0 +1,19 @@
+/*
+ * OptionsView.cpp
+ *
+ * Created on: Apr 14, 2012
+ * Author: Simon
+ */
+
+#include "OptionsView.h"
+
+OptionsView::OptionsView():
+ ui::Window(ui::Point(-1, -1), ui::Point(300, 300)){
+ // TODO Auto-generated constructor stub
+
+}
+
+OptionsView::~OptionsView() {
+ // TODO Auto-generated destructor stub
+}
+
diff --git a/src/options/OptionsView.h b/src/options/OptionsView.h
new file mode 100644
index 0000000..6a75f06
--- /dev/null
+++ b/src/options/OptionsView.h
@@ -0,0 +1,19 @@
+/*
+ * OptionsView.h
+ *
+ * Created on: Apr 14, 2012
+ * Author: Simon
+ */
+
+#ifndef OPTIONSVIEW_H_
+#define OPTIONSVIEW_H_
+
+#include "interface/Window.h"
+
+class OptionsView: public ui::Window {
+public:
+ OptionsView();
+ virtual ~OptionsView();
+};
+
+#endif /* OPTIONSVIEW_H_ */
diff --git a/src/search/SearchController.cpp b/src/search/SearchController.cpp
index 09fde71..b0936ef 100644
--- a/src/search/SearchController.cpp
+++ b/src/search/SearchController.cpp
@@ -121,14 +121,31 @@ void SearchController::ChangeSort()
{
searchModel->SetSort("new");
}
+ searchModel->UpdateSaveList(1, searchModel->GetLastQuery());
}
void SearchController::ShowOwn(bool show)
{
if(Client::Ref().GetAuthUser().ID)
+ {
+ searchModel->SetShowFavourite(false);
searchModel->SetShowOwn(show);
+ }
else
searchModel->SetShowOwn(false);
+ searchModel->UpdateSaveList(1, searchModel->GetLastQuery());
+}
+
+void SearchController::ShowFavourite(bool show)
+{
+ if(Client::Ref().GetAuthUser().ID)
+ {
+ searchModel->SetShowOwn(false);
+ searchModel->SetShowFavourite(show);
+ }
+ else
+ searchModel->SetShowFavourite(false);
+ searchModel->UpdateSaveList(1, searchModel->GetLastQuery());
}
void SearchController::Selected(int saveID, bool selected)
diff --git a/src/search/SearchController.h b/src/search/SearchController.h
index 3168419..ae13431 100644
--- a/src/search/SearchController.h
+++ b/src/search/SearchController.h
@@ -35,6 +35,7 @@ public:
void PrevPage();
void ChangeSort();
void ShowOwn(bool show);
+ void ShowFavourite(bool show);
void Selected(int saveID, bool selected);
void OpenSave(int saveID);
void Update();
diff --git a/src/search/SearchModel.cpp b/src/search/SearchModel.cpp
index e1d9849..76d0bb7 100644
--- a/src/search/SearchModel.cpp
+++ b/src/search/SearchModel.cpp
@@ -6,6 +6,7 @@
SearchModel::SearchModel():
currentSort("best"),
showOwn(false),
+ showFavourite(false),
loadedSave(NULL),
updateSaveListWorking(false),
updateSaveListFinished(false),
@@ -22,7 +23,12 @@ void * SearchModel::updateSaveListTHelper(void * obj)
void * SearchModel::updateSaveListT()
{
- vector<Save*> * tempSaveList = Client::Ref().SearchSaves((currentPage-1)*20, 20, lastQuery, currentSort=="new"?"date":"votes", showOwn, resultCount);
+ std::string category = "";
+ if(showFavourite)
+ category = "Favourites";
+ if(showOwn && Client::Ref().GetAuthUser().ID)
+ category = "by:"+Client::Ref().GetAuthUser().Username;
+ vector<Save*> * tempSaveList = Client::Ref().SearchSaves((currentPage-1)*20, 20, lastQuery, currentSort=="new"?"date":"votes", category, resultCount);
updateSaveListFinished = true;
return tempSaveList;
}
@@ -162,6 +168,15 @@ void SearchModel::notifyShowOwnChanged()
}
}
+void SearchModel::notifyShowFavouriteChanged()
+{
+ for(int i = 0; i < observers.size(); i++)
+ {
+ SearchView* cObserver = observers[i];
+ cObserver->NotifyShowOwnChanged(this);
+ }
+}
+
void SearchModel::notifySelectedChanged()
{
for(int i = 0; i < observers.size(); i++)
diff --git a/src/search/SearchModel.h b/src/search/SearchModel.h
index 8f2ae58..980c06d 100644
--- a/src/search/SearchModel.h
+++ b/src/search/SearchModel.h
@@ -24,11 +24,13 @@ private:
int currentPage;
int resultCount;
bool showOwn;
+ bool showFavourite;
void notifySaveListChanged();
void notifySelectedChanged();
void notifyPageChanged();
void notifySortChanged();
void notifyShowOwnChanged();
+ void notifyShowFavouriteChanged();
//Variables and methods for backgroun save request
bool saveListLoaded;
@@ -48,10 +50,12 @@ public:
int GetPageCount() { return max(1, (int)(ceil(resultCount/16))); }
int GetPageNum() { return currentPage; }
std::string GetLastQuery() { return lastQuery; }
- void SetSort(string sort) { currentSort = sort; UpdateSaveList(1, lastQuery); notifySortChanged(); }
+ void SetSort(string sort) { currentSort = sort; notifySortChanged(); }
string GetSort() { return currentSort; }
- void SetShowOwn(bool show) { if(show!=showOwn) { showOwn = show; UpdateSaveList(1, lastQuery); } notifyShowOwnChanged(); }
+ void SetShowOwn(bool show) { if(show!=showOwn) { showOwn = show; } notifyShowOwnChanged(); }
bool GetShowOwn() { return showOwn; }
+ void SetShowFavourite(bool show) { if(show!=showFavourite) { showFavourite = show; } notifyShowFavouriteChanged(); }
+ bool GetShowFavourite() { return showFavourite; }
void SetLoadedSave(Save * save);
Save * GetLoadedSave();
bool GetSavesLoaded() { return saveListLoaded; }
diff --git a/src/search/SearchView.cpp b/src/search/SearchView.cpp
index 5a1c6c7..ffaa471 100644
--- a/src/search/SearchView.cpp
+++ b/src/search/SearchView.cpp
@@ -27,7 +27,7 @@ SearchView::SearchView():
v->doSearch();
}
};
- searchField = new ui::Textbox(ui::Point(60, 10), ui::Point((XRES+BARSIZE)-((60*2)+16+10+50+10), 16), "");
+ searchField = new ui::Textbox(ui::Point(60, 10), ui::Point((XRES+BARSIZE)-226, 16), "");
searchField->SetAlignment(AlignLeft, AlignBottom);
searchField->SetActionCallback(new SearchAction(this));
@@ -41,7 +41,7 @@ SearchView::SearchView():
v->c->ChangeSort();
}
};
- sortButton = new ui::Button(ui::Point(XRES+BARSIZE-60-60-16-10+5, 10), ui::Point(60, 16), "Sort");
+ sortButton = new ui::Button(ui::Point(XRES+BARSIZE-140, 10), ui::Point(60, 16), "Sort");
sortButton->SetActionCallback(new SortAction(this));
sortButton->SetAlignment(AlignCentre, AlignBottom);
AddComponent(sortButton);
@@ -56,7 +56,7 @@ SearchView::SearchView():
v->c->ShowOwn(sender->GetToggleState());
}
};
- ownButton = new ui::Button(ui::Point(XRES+BARSIZE-60-16-10+10, 10), ui::Point(60, 16), "My Own");
+ ownButton = new ui::Button(ui::Point(XRES+BARSIZE-70, 10), ui::Point(60, 16), "My Own");
ownButton->SetTogglable(true);
ownButton->SetActionCallback(new MyOwnAction(this));
if(!Client::Ref().GetAuthUser().ID)
@@ -64,6 +64,25 @@ SearchView::SearchView():
ownButton->SetAlignment(AlignCentre, AlignBottom);
AddComponent(ownButton);
+ class FavAction : public ui::ButtonAction
+ {
+ SearchView * v;
+ public:
+ FavAction(SearchView * _v) { v = _v; }
+ void ActionCallback(ui::Button * sender)
+ {
+ v->c->ShowFavourite(sender->GetToggleState());
+ }
+ };
+ favButton = new ui::Button(searchField->Position+ui::Point(searchField->Size.X, 0), ui::Point(16, 16), "");
+ favButton->SetIcon(IconFavourite);
+ favButton->SetTogglable(true);
+ favButton->SetActionCallback(new FavAction(this));
+ if(!Client::Ref().GetAuthUser().ID)
+ favButton->Enabled = false;
+ favButton->SetAlignment(AlignCentre, AlignBottom);
+ AddComponent(favButton);
+
class NextPageAction : public ui::ButtonAction
{
SearchView * v;
@@ -206,6 +225,31 @@ void SearchView::NotifyShowOwnChanged(SearchModel * sender)
unpublishSelected->Enabled = true;
removeSelected->Enabled = true;
}
+ else if(sender->GetShowFavourite())
+ {
+ unpublishSelected->Enabled = false;
+ removeSelected->Enabled = true;
+ }
+ else
+ {
+ unpublishSelected->Enabled = false;
+ removeSelected->Enabled = false;
+ }
+}
+
+void SearchView::NotifyShowFavouriteChanged(SearchModel * sender)
+{
+ favButton->SetToggleState(sender->GetShowFavourite());
+ if(sender->GetShowFavourite())
+ {
+ unpublishSelected->Enabled = false;
+ removeSelected->Enabled = true;
+ }
+ else if(sender->GetShowOwn() || Client::Ref().GetAuthUser().UserElevation == ElevationAdmin || Client::Ref().GetAuthUser().UserElevation == ElevationModerator)
+ {
+ unpublishSelected->Enabled = true;
+ removeSelected->Enabled = true;
+ }
else
{
unpublishSelected->Enabled = false;
diff --git a/src/search/SearchView.h b/src/search/SearchView.h
index ed4b06e..6e27f06 100644
--- a/src/search/SearchView.h
+++ b/src/search/SearchView.h
@@ -19,6 +19,7 @@ class SearchView: public ui::Window
private:
SearchController * c;
vector<ui::SaveButton*> saveButtons;
+ ui::Button * favButton;
ui::Button * nextButton;
ui::Button * previousButton;
ui::Label * errorLabel;
@@ -39,6 +40,7 @@ public:
void NotifyPageChanged(SearchModel * sender);
void NotifySortChanged(SearchModel * sender);
void NotifyShowOwnChanged(SearchModel * sender);
+ void NotifyShowFavouriteChanged(SearchModel * sender);
SearchView();
virtual ~SearchView();
void AttachController(SearchController * _c) { c = _c; }