changeset 44:619cbd6e69f9

filesystem: fix CreateDirectories function
author Paper <mrpapersonic@gmail.com>
date Fri, 22 Sep 2023 13:52:11 -0400
parents eb9a78345ecb
children 4b05bc7668eb
files include/services/anilist.h include/services/services.h src/core/filesystem.cpp src/gui/dialog/settings/services.cpp src/gui/window.cpp src/services/anilist.cpp src/services/services.cpp
diffstat 7 files changed, 60 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/include/services/anilist.h	Fri Sep 22 12:06:49 2023 -0400
+++ b/include/services/anilist.h	Fri Sep 22 13:52:11 2023 -0400
@@ -7,7 +7,7 @@
 
 namespace Services::AniList {
 
-int AuthorizeUser();
+bool AuthorizeUser();
 
 /* Read queries */
 int GetAnimeList();
--- a/include/services/services.h	Fri Sep 22 12:06:49 2023 -0400
+++ b/include/services/services.h	Fri Sep 22 13:52:11 2023 -0400
@@ -4,8 +4,8 @@
 namespace Services {
 
 void Synchronize();
-void Authorize();
+bool Authorize();
 
 }; // namespace Services
 
-#endif // __services__services_h
\ No newline at end of file
+#endif // __services__services_h
--- a/src/core/filesystem.cpp	Fri Sep 22 12:06:49 2023 -0400
+++ b/src/core/filesystem.cpp	Fri Sep 22 13:52:11 2023 -0400
@@ -26,6 +26,7 @@
 	std::string temp = "";
 	size_t start;
 	size_t end = 0;
+	temp.append(path.substr(0, path.find_first_not_of(DELIM, end)));
 
 	while ((start = path.find_first_not_of(DELIM, end)) != std::string::npos) {
 		end = path.find(DELIM, start);
@@ -35,8 +36,9 @@
 			/* ERROR_PATH_NOT_FOUND should NOT happen here */
 			return false;
 #else
-		if (mkdir(temp.c_str(), 0755))
-			return false;
+		struct stat st;
+		if (stat(temp.c_str(), &st) == -1)
+			mkdir(temp.c_str(), 0755);
 #endif
 		temp.append(DELIM);
 	}
--- a/src/gui/dialog/settings/services.cpp	Fri Sep 22 12:06:49 2023 -0400
+++ b/src/gui/dialog/settings/services.cpp	Fri Sep 22 13:52:11 2023 -0400
@@ -46,6 +46,8 @@
 	QGroupBox* group_box = new QGroupBox(tr("Account"), result);
 	group_box->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
 
+	/* this is outdated! usernames are retrieved through a request to AniList now.
+           although that's a bit... erm... cancerous, maybe this method IS useful. IDK */
 	QLabel* username_entry_label = new QLabel(tr("Username: (not your email address)"), group_box);
 
 	QWidget* auth_widget = new QWidget(group_box);
--- a/src/gui/window.cpp	Fri Sep 22 12:06:49 2023 -0400
+++ b/src/gui/window.cpp	Fri Sep 22 13:52:11 2023 -0400
@@ -121,6 +121,46 @@
 		SettingsDialog dialog(this);
 		dialog.exec();
 	});
+	action->setMenuRole(QAction::PreferencesRole);
+
+	menu = menubar->addMenu("&View");
+
+	std::map<QAction*, int> page_to_index_map = {};
+
+	QActionGroup* pages_group = new QActionGroup(this);
+	pages_group->setExclusive(true);
+
+	action = pages_group->addAction(menu->addAction("&Now Playing"));
+	page_to_index_map[action] = 0;
+	action = pages_group->addAction(menu->addAction("&Anime List"));
+	page_to_index_map[action] = 1;
+	action->setChecked(true);
+	action = pages_group->addAction(menu->addAction("&History"));
+	page_to_index_map[action] = 2;
+	action = pages_group->addAction(menu->addAction("&Statistics"));
+	page_to_index_map[action] = 3;
+	action = pages_group->addAction(menu->addAction("S&earch"));
+	page_to_index_map[action] = 4;
+	action = pages_group->addAction(menu->addAction("Se&asons"));
+	page_to_index_map[action] = 5;
+	action = pages_group->addAction(menu->addAction("&Torrents"));
+	page_to_index_map[action] = 6;
+
+	connect(pages_group, &QActionGroup::triggered, this, [page_to_index_map, stack](QAction* action) {
+		int index = page_to_index_map.at(action);
+		switch (index) {
+			case 0:
+			case 1: stack->setCurrentIndex(index); break;
+			case 3: stack->setCurrentIndex(2);
+			default: break;
+		}
+	});
+
+	menu = menubar->addMenu("&Help");
+	action = menu->addAction("About &Qt", qApp, [this]{
+		qApp->aboutQt();
+	});
+	action->setMenuRole(QAction::AboutQtRole);
 
 	setMenuBar(menubar);
 
--- a/src/services/anilist.cpp	Fri Sep 22 12:06:49 2023 -0400
+++ b/src/services/anilist.cpp	Fri Sep 22 13:52:11 2023 -0400
@@ -309,7 +309,7 @@
 	return account.UserId();
 }
 
-int AuthorizeUser() {
+bool AuthorizeUser() {
 	/* Prompt for PIN */
 	QDesktopServices::openUrl(
 	    QUrl("https://anilist.co/api/v2/oauth/authorize?client_id=" CLIENT_ID "&response_type=token"));
@@ -320,7 +320,7 @@
 	if (ok && !token.isEmpty())
 		account.SetAuthToken(token.toStdString());
 	else // fail
-		return 0;
+		return false;
 	const std::string query = "query {\n"
 	                          "  Viewer {\n"
 	                          "    id\n"
@@ -331,11 +331,11 @@
 	                          "  }\n"
 	                          "}\n";
 	nlohmann::json json = {
-	    {"query", query}
-    };
+		{"query", query}
+	};
 	auto ret = nlohmann::json::parse(SendRequest(json.dump()));
 	ParseUser(json["Viewer"]);
-	return 1;
+	return true;
 }
 
 } // namespace Services::AniList
--- a/src/services/services.cpp	Fri Sep 22 12:06:49 2023 -0400
+++ b/src/services/services.cpp	Fri Sep 22 13:52:11 2023 -0400
@@ -11,11 +11,13 @@
 	}
 }
 
-void Authorize() {
+bool Authorize() {
 	switch (session.config.service) {
-		case Anime::Services::ANILIST: AniList::AuthorizeUser(); break;
-		default: break;
+		case Anime::Services::ANILIST:
+			return AniList::AuthorizeUser();
+		default:
+			return true;
 	}
 }
 
-}; // namespace Services
\ No newline at end of file
+}; // namespace Services