forked from JDimproved/JDim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bbslistadmin.cpp
288 lines (206 loc) · 8.21 KB
/
bbslistadmin.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
// ライセンス: GPL2
//#define _DEBUG
#include "jddebug.h"
#include "bbslistadmin.h"
#include "bbslistviewbase.h"
#include "toolbar.h"
#include "skeleton/view.h"
#include "skeleton/dragnote.h"
#include "skeleton/undobuffer.h"
#include "jdlib/miscutil.h"
#include "global.h"
#include "viewfactory.h"
#include "session.h"
#include "command.h"
// お気に入りの共通UNDOバッファ
SKELETON::UNDO_BUFFER *instance_undo_buffer_favorite = NULL;
SKELETON::UNDO_BUFFER* BBSLIST::get_undo_buffer_favorite()
{
if( ! instance_undo_buffer_favorite ) instance_undo_buffer_favorite = new SKELETON::UNDO_BUFFER();
assert( instance_undo_buffer_favorite );
return instance_undo_buffer_favorite;
}
void BBSLIST::delete_undo_buffer_favorite()
{
if( instance_undo_buffer_favorite ) delete instance_undo_buffer_favorite;
instance_undo_buffer_favorite = NULL;
}
//////////////////////////////////////////////
BBSLIST::BBSListAdmin *instance_bbslistadmin = NULL;
BBSLIST::BBSListAdmin* BBSLIST::get_admin()
{
if( ! instance_bbslistadmin ) instance_bbslistadmin = new BBSLIST::BBSListAdmin( URL_BBSLISTADMIN );
assert( instance_bbslistadmin );
return instance_bbslistadmin;
}
void BBSLIST::delete_admin()
{
if( instance_bbslistadmin ) delete instance_bbslistadmin;
instance_bbslistadmin = NULL;
}
//////////////////////////////////////////////
using namespace BBSLIST;
BBSListAdmin::BBSListAdmin( const std::string& url )
: SKELETON::Admin( url ), m_toolbar( NULL )
{
get_notebook()->set_dragable( false );
get_notebook()->set_fixtab( true );
}
BBSListAdmin::~BBSListAdmin()
{
#ifdef _DEBUG
std::cout << "BBSListAdmin::~BBSListAdmin\n";
#endif
if( m_toolbar ) delete m_toolbar;
BBSLIST::delete_undo_buffer_favorite();
}
void BBSListAdmin::save_session()
{
Admin::save_session();
// bbslistのページの位置保存
SESSION::set_bbslist_page( get_current_page() );
}
// 前回開いていたURLを復元
void BBSListAdmin::restore( const bool only_locked )
{
COMMAND_ARGS command_arg;
// 板一覧
// 初回起動時は板一覧の読み込みもここで行われる
command_arg = url_to_openarg( URL_BBSLISTVIEW, true, false );
open_view( command_arg );
// お気に入り
command_arg = url_to_openarg( URL_FAVORITEVIEW, true, false );
open_view( command_arg );
// スレ履歴
command_arg = url_to_openarg( URL_HISTTHREADVIEW, true, false );
open_view( command_arg );
// 板履歴
command_arg = url_to_openarg( URL_HISTBOARDVIEW, true, false );
open_view( command_arg );
// 最近閉じたスレ
command_arg = url_to_openarg( URL_HISTCLOSEVIEW, true, false );
open_view( command_arg );
// 最近閉じた板
command_arg = url_to_openarg( URL_HISTCLOSEBOARDVIEW, true, false );
open_view( command_arg );
// 最近閉じた画像
command_arg = url_to_openarg( URL_HISTCLOSEIMGVIEW, true, false );
open_view( command_arg );
set_command( "set_page", std::string(), MISC::itostr( SESSION::bbslist_page() ) );
set_command( "hide_tabs" );
}
COMMAND_ARGS BBSListAdmin::url_to_openarg( const std::string& url, const bool tab, const bool lock )
{
COMMAND_ARGS command_arg;
command_arg.command = "open_view";
command_arg.url = url;
if( tab ) command_arg.arg1 = "true"; // タブで開く
return command_arg;
}
void BBSListAdmin::switch_admin()
{
if( ! has_focus() ) CORE::core_set_command( "switch_sidebar" );
}
//
// ツールバー表示
//
void BBSListAdmin::show_toolbar()
{
// まだ作成されていない場合は作成する
if( ! m_toolbar ){
m_toolbar = new BBSListToolBar();
get_notebook()->append_toolbar( *m_toolbar );
if( SESSION::get_show_bbslist_toolbar() ) m_toolbar->open_buttonbar();
}
get_notebook()->show_toolbar();
}
//
// ツールバー表示/非表示切り替え
//
void BBSListAdmin::toggle_toolbar()
{
if( ! m_toolbar ) return;
if( SESSION::get_show_bbslist_toolbar() ){
m_toolbar->open_buttonbar();
m_toolbar->show_toolbar();
}
else m_toolbar->close_buttonbar();
}
SKELETON::View* BBSListAdmin::create_view( const COMMAND_ARGS& command )
{
int type = CORE::VIEW_NONE;
if( command.url == URL_BBSLISTVIEW ) type = CORE::VIEW_BBSLISTVIEW;
if( command.url == URL_FAVORITEVIEW ) type = CORE::VIEW_FAVORITELIST;
if( command.url == URL_HISTTHREADVIEW ) type = CORE::VIEW_HISTTHREAD;
if( command.url == URL_HISTCLOSEVIEW ) type = CORE::VIEW_HISTCLOSE;
if( command.url == URL_HISTBOARDVIEW ) type = CORE::VIEW_HISTBOARD;
if( command.url == URL_HISTCLOSEBOARDVIEW ) type = CORE::VIEW_HISTCLOSEBOARD;
if( command.url == URL_HISTCLOSEIMGVIEW ) type = CORE::VIEW_HISTCLOSEIMG;
CORE::VIEWFACTORY_ARGS view_args;
view_args.arg1 = command.arg4;
view_args.arg2 = command.arg5;
SKELETON::View* view = CORE::ViewFactory( type, command.url, view_args );
return view;
}
//
// ローカルなコマンド
//
void BBSListAdmin::command_local( const COMMAND_ARGS& command )
{
SKELETON::View* view = get_view( command.url );
if( view ){
// アイテム追加
// 共有バッファにコピーデータをセットしておくこと
if( command.command == "append_item" ) view->set_command( "append_item" );
// 履歴のセット
// 先頭にアイテムを追加する。ツリーにアイテムが含まれている場合は移動する
// 共有バッファにコピーデータをセットしておくこと
else if( command.command == "append_history" ) view->set_command( "append_history" );
// 項目削除
else if( command.command == "remove_item" ) view->set_command( "remove_item", command.arg1 );
// 先頭項目削除
else if( command.command == "remove_headitem" ) view->set_command( "remove_headitem" );
// 全項目削除
else if( command.command == "remove_allitems" ) view->set_command( "remove_allitems" );
// ツリーの編集
else if( command.command == "edit_tree" ) view->set_command( "edit_tree" );
// お気に入りルート更新チェック
else if( command.command == "check_update_root" ) view->set_command( "check_update_root" );
else if( command.command == "check_update_open_root" ) view->set_command( "check_update_open_root" );
else if( command.command == "cancel_check_update" ) view->set_command( "cancel_check_update" );
// お気に入りのスレの url と 名前を変更
else if( command.command == "replace_thread" ) view->set_command( "replace_thread", command.arg1, command.arg2 );
// XML保存
else if( command.command == "save_xml" ) view->set_command( "save_xml" );
// スレのアイコン表示を更新
else if( command.command == "toggle_articleicon" ) view->set_command( "toggle_articleicon", command.arg1 );
// 板のアイコン表示を更新
else if( command.command == "toggle_boardicon" ) view->set_command( "toggle_boardicon", command.arg1 );
}
// URLを選択
if( command.command == "select_item" ){
view = get_current_view();
if( view ) view->set_command( "select_item", command.arg1 );
}
}
// 履歴を DATA_INFO_LIST 型で取得
void BBSListAdmin::get_history( const std::string& url, CORE::DATA_INFO_LIST& info_list )
{
info_list.clear();
BBSListViewBase* view = dynamic_cast< BBSListViewBase* >( get_view( url ) );
if( view ) return view->get_history( info_list );
}
// サイドバーの指定したidのディレクトリに含まれるスレのアドレスを取得
void BBSListAdmin::get_threads( const std::string& url, const int dirid, std::vector< std::string >& list_url )
{
list_url.clear();
BBSListViewBase* view = dynamic_cast< BBSListViewBase* >( get_view( url ) );
if( view ) view->get_threads( dirid, list_url );
}
// サイドバーの指定したidのディレクトリの名前を取得
std::string BBSListAdmin::get_dirname( const std::string& url, const int dirid )
{
BBSListViewBase* view = dynamic_cast< BBSListViewBase* >( get_view( url ) );
if( view ) return view->get_dirname( dirid );
return std::string();
}