annotate src/window.cpp @ 2:23d0d9319a00

Update Also converted everything to LF from CRLF
author Paper <mrpapersonic@gmail.com>
date Sat, 12 Aug 2023 03:16:26 -0400
parents 1ae666fdf9e2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
1 #include "window.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
2 #include <curl/curl.h>
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
3 #include "page.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
4 #include "config.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
5 #include "anime.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
6 #include "statistics.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
7 #include "now_playing.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
8 #include "16x16/document-list.png.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
9 #include "16x16/film.png.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
10 #include "16x16/chart.png.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
11 #include "16x16/clock-history-frame.png.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
12 #include "16x16/magnifier.png.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
13 #include "16x16/calendar.png.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
14 #include "16x16/feed.png.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
15 #include "24x24/arrow-circle-double-135.png.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
16 #include "24x24/folder-open.png.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
17 #include "24x24/gear.png.h"
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
18
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
19 Config Weeaboo::config = Config();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
20
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
21 WeeabooFrame::WeeabooFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
22 : wxFrame(NULL, wxID_ANY, title, pos, size) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
23 /* ---- Menu Bar ---- */
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
24 wxMenu* library_folders_submenu = new wxMenu;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
25 library_folders_submenu->Append(ID_AddLibraryFolder, "&Add library folder");
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
26 library_folders_submenu->Append(ID_ScanLibraryFolders, "&Rescan library folders");
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
27
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
28 wxMenu* file_menu = new wxMenu;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
29 file_menu->AppendSubMenu(library_folders_submenu, "&Library folders");
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
30 file_menu->Append(ID_SyncAnimeList, "&Sync anime list\tCtrl+S");
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
31 file_menu->AppendSeparator();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
32 file_menu->Append(ID_PlayNextEpisode, "Play &next episode\tCtrl+N");
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
33 file_menu->Append(ID_PlayRandomEpisode, "Play &random episode\tCtrl+R");
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
34 file_menu->AppendSeparator();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
35 file_menu->Append(wxID_EXIT);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
36
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
37 wxMenu* help_menu = new wxMenu;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
38 help_menu->Append(wxID_ABOUT);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
39
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
40 wxMenuBar* menu_bar = new wxMenuBar;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
41 menu_bar->Append(file_menu, "&File");
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
42 menu_bar->Append(help_menu, "&Help");
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
43
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
44 SetMenuBar(menu_bar);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
45
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
46 /* Toolbar */
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
47 wxToolBar* top_toolbar = CreateToolBar();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
48 top_toolbar->SetToolBitmapSize(wxSize(24,24));
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
49 top_toolbar->AddTool(ID_ToolbarSync, wxT("Sync"), wxBITMAP_PNG_FROM_DATA(arrow_circle_double_135));
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
50 top_toolbar->Realize();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
51
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
52 /* ---- Sidebar ---- */
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
53 /* This first panel is only for the sizer... */
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
54 wxPanel* left_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(140, 600), wxTAB_TRAVERSAL, wxPanelNameStr);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
55 wxPanel* left_panel_inside = new wxPanel(left_panel, wxID_ANY, wxPoint(6, 6), wxSize(128, 588), wxTAB_TRAVERSAL);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
56 wxToolBar* left_toolbar = new wxToolBar(left_panel_inside, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_FLAT | wxTB_VERTICAL | wxTB_HORZ_TEXT | wxTB_NODIVIDER);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
57 left_toolbar->SetMargins(6, 6);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
58 left_toolbar->SetToolBitmapSize(wxSize(16,16));
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
59 left_toolbar->AddRadioTool(ID_NowPlaying, "Now Playing", wxBITMAP_PNG_FROM_DATA(film));
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
60 left_toolbar->AddRadioTool(ID_AnimeList, "Anime List", wxBITMAP_PNG_FROM_DATA(document_list));
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
61 left_toolbar->AddRadioTool(ID_History, "History", wxBITMAP_PNG_FROM_DATA(clock_history_frame));
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
62 left_toolbar->AddRadioTool(ID_Statistics, "Statistics", wxBITMAP_PNG_FROM_DATA(chart));
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
63 left_toolbar->AddRadioTool(ID_Search, "Search", wxBITMAP_PNG_FROM_DATA(magnifier));
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
64 left_toolbar->AddRadioTool(ID_Seasons, "Seasons", wxBITMAP_PNG_FROM_DATA(calendar));
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
65 left_toolbar->AddRadioTool(ID_Torrents, "Torrents", wxBITMAP_PNG_FROM_DATA(feed));
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
66
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
67 /* ---- Initialize our pages ---- */
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
68 wxPanel* right_panel = new wxPanel(this, wxID_ANY, wxPoint(140, 0), wxSize(460, 600), wxTAB_TRAVERSAL, wxPanelNameStr);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
69 now_playing = new NowPlaying(&pages[PAGE_NOW_PLAYING], right_panel);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
70 anime_list = new AnimeListPage(&pages[PAGE_ANIME_LIST], right_panel);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
71 anime_list->SyncAnimeList();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
72 anime_list->LoadAnimeList(this);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
73 statistics = new Statistics(&pages[PAGE_STATISTICS], right_panel);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
74
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
75 status.current_page = PAGE_ANIME_LIST; // The below function depends on this value being set?
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
76 set_page(PAGE_ANIME_LIST);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
77 left_toolbar->ToggleTool(ID_AnimeList, true);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
78 left_toolbar->Realize();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
79
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
80 wxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
81 sizer->Add(left_panel, 0, wxEXPAND, 10);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
82 sizer->Add(right_panel, 1, wxEXPAND, 10);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
83 sizer->SetMinSize(600, 600);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
84 this->SetSizer(sizer);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
85 sizer->SetSizeHints(this);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
86
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
87 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
88
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
89 bool Weeaboo::OnInit() {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
90 config.Load();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
91 if (curl_global_init(CURL_GLOBAL_DEFAULT) != 0) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
92 wxMessageBox("libcurl failed to initialize!",
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
93 "Error", wxOK | wxICON_ERROR);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
94 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
95 wxSystemOptions::SetOption("msw.remap",
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
96 wxSystemOptions::HasOption("msw.remap")
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
97 ? wxSystemOptions::GetOptionInt("msw.remap")
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
98 : wxDisplayDepth() <= 8 ? 1 : 2
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
99 );
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
100 wxImage::AddHandler(new wxPNGHandler);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
101 frame = new WeeabooFrame("Weeaboo", wxPoint(50, 50), wxSize(450, 340));
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
102 frame->Show(true);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
103 return true;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
104 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
105
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
106 #define TOOLBAR_HANDLER(name, page) \
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
107 void WeeabooFrame::name(wxCommandEvent& event) { \
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
108 set_page(page); \
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
109 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
110 TOOLBAR_HANDLER(OnNowPlaying, PAGE_NOW_PLAYING)
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
111 TOOLBAR_HANDLER(OnAnimeList, PAGE_ANIME_LIST)
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
112 TOOLBAR_HANDLER(OnHistory, PAGE_HISTORY)
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
113 TOOLBAR_HANDLER(OnStatistics, PAGE_STATISTICS)
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
114 TOOLBAR_HANDLER(OnSearch, PAGE_SEARCH)
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
115 TOOLBAR_HANDLER(OnSeasons, PAGE_SEASONS)
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
116 TOOLBAR_HANDLER(OnTorrents, PAGE_TORRENTS)
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
117 #undef TOOLBAR_HANDLER
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
118
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
119 void WeeabooFrame::OnClose(wxCloseEvent& event) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
120 Weeaboo::config.Save();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
121 curl_global_cleanup();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
122 delete anime_list;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
123 event.Skip();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
124 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
125
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
126 void WeeabooFrame::OnExit(wxCommandEvent& event) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
127 Close(true);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
128 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
129
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
130 void WeeabooFrame::OnAbout(wxCommandEvent& event) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
131 wxMessageBox("To be written",
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
132 "About Weeaboo", wxOK | wxICON_INFORMATION);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
133 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
134
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
135 void WeeabooFrame::OnAddFolder(wxCommandEvent& event) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
136 wxLogMessage("OnAddFolder");
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
137 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
138
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
139 void WeeabooFrame::OnScanFolders(wxCommandEvent& event) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
140 wxLogMessage("OnScanFolders");
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
141 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
142
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
143 void WeeabooFrame::OnNextEpisode(wxCommandEvent& event) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
144 wxLogMessage("OnNextEpisode");
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
145 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
146
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
147 void WeeabooFrame::OnSyncList(wxCommandEvent& event) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
148 anime_list->SyncAnimeList();
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
149 anime_list->LoadAnimeList(this);
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
150 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
151
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
152 void WeeabooFrame::OnRandomEpisode(wxCommandEvent& event) {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
153 wxLogMessage("OnRandomEpisode");
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
154 }
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
155
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
156 AnimeListPage* WeeabooFrame::GetAnimeList() {
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
157 return anime_list;
Paper <mrpapersonic@gmail.com>
parents: 1
diff changeset
158 }