comparison src/window.cpp @ 1:1ae666fdf9e2

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