-
Notifications
You must be signed in to change notification settings - Fork 11
/
boardviewbase.cpp
3109 lines (2380 loc) · 87.6 KB
/
boardviewbase.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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ライセンス: GPL2
//#define _DEBUG
#include "jddebug.h"
#include "gtkmmversion.h"
#include "boardadmin.h"
#include "boardview.h"
#include "skeleton/msgdiag.h"
#include "skeleton/filediag.h"
#include "jdlib/miscutil.h"
#include "jdlib/miscgtk.h"
#include "jdlib/jdregex.h"
#include "dbtree/interface.h"
#include "dbtree/articlebase.h"
#include "config/globalconf.h"
#include "control/controlid.h"
#include "control/controlutil.h"
#include "command.h"
#include "cache.h"
#include "session.h"
#include "sharedbuffer.h"
#include "global.h"
#include "type.h"
#include "prefdiagfactory.h"
#include "httpcode.h"
#include "colorid.h"
#include "fontid.h"
#include "compmanager.h"
#include "dndmanager.h"
#include "icons/iconmanager.h"
#include <sstream>
using namespace BOARD;
// row -> path
#define GET_PATH( row ) m_liststore->get_path( row )
enum{
CANCEL_OPENROW = 500, // msec 連続クリック防止用カウンタ
DEFAULT_COLMUN_WIDTH = 50
};
enum{
COL_MARKVAL_OLD = -2, // dat 落ち
COL_MARKVAL_FINISHED = -1, // キャッシュあり、新着無し、規定スレ数を越えている
COL_MARKVAL_NORMAL = 0, // 通常状態、キャッシュ無し、
COL_MARKVAL_924, // スレッド924、キャッシュ無し
COL_MARKVAL_NEWTHREAD_HOUR, // 新スレ( CONFIG::get_newthread_hour 時間以内 )、キャッシュ無し
COL_MARKVAL_NEWTHREAD, // 前回の板一覧読み込み時から新しく出来たスレ、キャッシュ無し
COL_MARKVAL_CACHED, // キャッシュあり、新着無し
COL_MARKVAL_BROKEN_SUBJECT, // キャッシュあり、新着無しだが subject.txt が壊れている可能性がある
COL_MARKVAL_UPDATED, // キャッシュあり、新着有り
COL_MARKVAL_BKMARKED, // ブックマークされている、新着無し
COL_MARKVAL_BKMARKED_BROKEN_SUBJECT, // ブックマークされている、新着無しだが subject.txt が壊れている可能性がある
COL_MARKVAL_BKMARKED_UPDATED // ブックマークされている、新着有り
};
// 昇順で上か下か
enum{
COL_A_UP = -1,
COL_B_UP = 1,
};
enum
{
BOOKMARK_AUTO = -1,
BOOKMARK_UNSET = 0,
BOOKMARK_SET = 1
};
#define DELETE_COLUMN(col) do{ if( ! col ) { delete col; col = NULL; } }while(0)
// set_sizing( Gtk::TREE_VIEW_COLUMN_FIXED ) を指定して append_columnする
#define APPEND_COLUMN(col,title,model) do{ \
col = Gtk::manage( new Gtk::TreeViewColumn( title, model ) ); \
col->set_sizing( Gtk::TREE_VIEW_COLUMN_FIXED ); \
m_treeview.append_column( *col ); \
}while(0)
BoardViewBase::BoardViewBase( const std::string& url, const bool show_col_board )
: SKELETON::View( url ),
m_treeview( url, DNDTARGET_FAVORITE, true, CONFIG::get_fontname( FONT_BOARD ), COLOR_CHAR_BOARD, COLOR_BACK_BOARD, COLOR_BACK_BOARD_EVEN ),
m_col_mark( NULL ),
m_col_id( NULL ),
m_col_board( NULL ),
m_col_subject( NULL ),
m_col_res( NULL ),
m_col_str_load( NULL ),
m_col_str_new( NULL ),
m_col_since( NULL ),
m_col_write( NULL ),
m_col_access( NULL ),
m_col_speed( NULL ),
m_col_diff( NULL ),
m_clicked( false ),
m_col( COL_NUM_COL ),
m_previous_col( COL_NUM_COL ),
m_sortmode( SORTMODE_ASCEND ),
m_previous_sortmode( false ),
m_loading( false ),
m_enable_menuslot( true ),
m_load_subject_txt( true ),
m_show_col_board( show_col_board ),
m_col_diff_is_shown( false ),
m_cancel_openrow_counter( 0 )
{
// 次スレ検索ビューのようにURLの途中に http が入っている場合は取り除く
size_t pos = url.rfind( "http://" );
if( pos == std::string::npos || pos == 0 ) pos = url.rfind( "https://" );
if( pos != std::string::npos && pos != 0 ) m_url_board = DBTREE::url_subject( url.substr( 0, pos ) );
else m_url_board = DBTREE::url_subject( url );
m_scrwin.add( m_treeview );
m_scrwin.set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_ALWAYS );
pack_start( m_scrwin );
show_all_children();
// ツリービュー設定
m_liststore = Gtk::ListStore::create( m_columns );
#if !GTKMM_CHECK_VERSION(2,7,0)
// gtkmm26以下にはunset_model()が無いのでここでset_model()しておく
m_treeview.set_model( m_liststore );
#endif
#if GTKMM_CHECK_VERSION(2,6,0)
// セルを固定の高さにする
// append_column する前に columnに対して set_sizing( Gtk::TREE_VIEW_COLUMN_FIXED ) すること
m_treeview.set_fixed_height_mode( true );
#ifdef _DEBUG
std::cout << "BoardViewBase::BoardViewBase : m_treeview.set_fixed_height_mode\n";
#endif
#endif
// 列のappend
update_columns();
// ソート関数セット
m_liststore->set_sort_func( COL_MARK, sigc::mem_fun( *this, &BoardViewBase::slot_compare_row ) );
m_liststore->set_sort_func( COL_ID, sigc::mem_fun( *this, &BoardViewBase::slot_compare_row ) );
m_liststore->set_sort_func( COL_BOARD, sigc::mem_fun( *this, &BoardViewBase::slot_compare_row ) );
m_liststore->set_sort_func( COL_SUBJECT, sigc::mem_fun( *this, &BoardViewBase::slot_compare_row ) );
m_liststore->set_sort_func( COL_RES, sigc::mem_fun( *this, &BoardViewBase::slot_compare_row ) );
m_liststore->set_sort_func( COL_STR_LOAD, sigc::mem_fun( *this, &BoardViewBase::slot_compare_row ) );
m_liststore->set_sort_func( COL_STR_NEW, sigc::mem_fun( *this, &BoardViewBase::slot_compare_row ) );
m_liststore->set_sort_func( COL_SINCE, sigc::mem_fun( *this, &BoardViewBase::slot_compare_row ) );
m_liststore->set_sort_func( COL_WRITE, sigc::mem_fun( *this, &BoardViewBase::slot_compare_row ) );
m_liststore->set_sort_func( COL_ACCESS, sigc::mem_fun( *this, &BoardViewBase::slot_compare_row ) );
m_liststore->set_sort_func( COL_SPEED, sigc::mem_fun( *this, &BoardViewBase::slot_compare_row ) );
m_liststore->set_sort_func( COL_DIFF, sigc::mem_fun( *this, &BoardViewBase::slot_compare_row ) );
m_treeview.sig_button_press().connect( sigc::mem_fun(*this, &BoardViewBase::slot_button_press ) );
m_treeview.sig_button_release().connect( sigc::mem_fun(*this, &BoardViewBase::slot_button_release ) );
m_treeview.sig_motion_notify().connect( sigc::mem_fun(*this, &BoardViewBase::slot_motion_notify ) );
m_treeview.sig_key_press().connect( sigc::mem_fun(*this, &BoardViewBase::slot_key_press ) );
m_treeview.sig_key_release().connect( sigc::mem_fun(*this, &BoardViewBase::slot_key_release ) );
m_treeview.sig_scroll_event().connect( sigc::mem_fun(*this, &BoardViewBase::slot_scroll_event ) );
m_treeview.set_has_tooltip( true );
m_treeview.signal_query_tooltip().connect( sigc::mem_fun(*this, &BoardViewBase::slot_query_tooltip) );
m_treeview.signal_drag_data_get().connect( sigc::mem_fun(*this, &BoardViewBase::slot_drag_data_get ) );
m_treeview.sig_dropped_uri_list().connect( sigc::mem_fun(*this, &BoardViewBase::slot_dropped_url_list ) );
// アクション初期化
setup_action();
// マウスジェスチャ可能
set_enable_mg( true );
// コントロールモード設定
get_control().add_mode( CONTROL::MODE_BOARD );
}
BoardViewBase::~BoardViewBase() noexcept
{
#ifdef _DEBUG
std::cout << "BoardViewBase::~BoardViewBase : " << get_url() << std::endl;
#endif
}
SKELETON::Admin* BoardViewBase::get_admin()
{
return BOARD::get_admin();
}
//
// url 更新
//
// 移転があったときなどにadminから呼び出される
//
void BoardViewBase::update_url( const std::string& url_old, const std::string& url_new )
{
if( m_url_board.find( url_old ) == 0 ) m_url_board = url_new + m_url_board.substr( url_old.length() );
SKELETON::View::update_url( url_old, url_new );
}
// アイコンのID取得
int BoardViewBase::get_icon( const std::string& iconname ) const
{
int id = ICON::NONE;
if( iconname == "default" ) id = ICON::BOARD;
if( iconname == "loading" ) id = ICON::LOADING;
if( iconname == "loading_stop" ) id = ICON::LOADING_STOP;
if( iconname == "update" ) id = ICON::BOARD_UPDATE; // 更新チェックして更新があった場合
if( iconname == "updated" ) id = ICON::BOARD_UPDATED;
#ifdef _DEBUG
std::cout << "BoardViewBase::get_icon : " << iconname << " url = " << get_url() << std::endl;
#endif
return id;
}
//
// コピー用URL(メインウィンドウのURLバーなどに表示する)
//
std::string BoardViewBase::url_for_copy() const
{
return DBTREE::url_boardbase( get_url_board() );
}
//
// アクション初期化
//
void BoardViewBase::setup_action()
{
#ifdef _DEBUG
std::cout << "BoardViewBase::setup_action\n";
#endif
// アクショングループを作ってUIマネージャに登録
action_group() = Gtk::ActionGroup::create();
action_group()->add( Gtk::Action::create( "BookMark", ITEM_NAME_BOOKMARK "(_B)" ),
sigc::bind< int >( sigc::mem_fun( *this, &BoardViewBase::slot_bookmark ), BOOKMARK_AUTO ) );
action_group()->add( Gtk::Action::create( "SetBookMark", "しおりを設定(_S)" ), // 未使用
sigc::bind< int >( sigc::mem_fun( *this, &BoardViewBase::slot_bookmark ), BOOKMARK_SET ) );
action_group()->add( Gtk::Action::create( "UnsetBookMark", "しおりを解除(_U)" ), // 未使用
sigc::bind< int >( sigc::mem_fun( *this, &BoardViewBase::slot_bookmark ), BOOKMARK_UNSET ) );
action_group()->add( Gtk::Action::create( "OpenTab", "OpenArticleTab" ), sigc::mem_fun( *this, &BoardViewBase::slot_open_tab ) );
action_group()->add( Gtk::Action::create( "RegetArticle", ITEM_NAME_REGETARTICLE "(_R)" ),
sigc::mem_fun( *this, &BoardViewBase::slot_reget_article ) );
action_group()->add( Gtk::Action::create( "Favorite_Article", ITEM_NAME_FAVORITE_ARTICLE "(_F)..." ),
sigc::mem_fun( *this, &BoardViewBase::slot_favorite_thread ) );
action_group()->add( Gtk::Action::create( "Favorite_Board", "板をお気に入りに追加(_A)" ), sigc::mem_fun( *this, &BoardViewBase::slot_favorite_board ) );
action_group()->add( Gtk::Action::create( "GotoTop", "一番上に移動(_T)" ), sigc::mem_fun( *this, &BoardViewBase::goto_top ) );
action_group()->add( Gtk::Action::create( "GotoBottom", "一番下に移動(_M)" ), sigc::mem_fun( *this, &BoardViewBase::goto_bottom ) );
action_group()->add( Gtk::Action::create( "Delete_Menu", "Delete" ) );
action_group()->add( Gtk::Action::create( "Delete", "選択した行のログを削除する(_D)" ), sigc::mem_fun( *this, &BoardViewBase::slot_delete_logs ) );
action_group()->add( Gtk::Action::create( "OpenRows", "選択したスレを開く(_O)" ),
sigc::bind< bool >( sigc::mem_fun( *this, &BoardViewBase::open_selected_rows ), false ) );
action_group()->add( Gtk::Action::create( "RegetRows", "スレ情報を消さずにスレを再取得(_R)" ),
sigc::bind< bool >( sigc::mem_fun( *this, &BoardViewBase::open_selected_rows ), true ) );
action_group()->add( Gtk::Action::create( "CopyURL", ITEM_NAME_COPY_URL "(_U)" ), sigc::mem_fun( *this, &BoardViewBase::slot_copy_url ) );
action_group()->add( Gtk::Action::create( "CopyTitleURL", ITEM_NAME_COPY_TITLE_URL "(_L)" ),
sigc::mem_fun( *this, &BoardViewBase::slot_copy_title_url ) );
action_group()->add( Gtk::Action::create( "OpenBrowser", ITEM_NAME_OPEN_BROWSER "(_W)" ),
sigc::mem_fun( *this, &BoardViewBase::slot_open_browser ) );
action_group()->add( Gtk::Action::create( "AboneThread", ITEM_NAME_ABONE_ARTICLE "(_N)" ),
sigc::mem_fun( *this, &BoardViewBase::slot_abone_thread ) );
action_group()->add( Gtk::Action::create( "PreferenceArticle", ITEM_NAME_PREF_THREAD "(_P)..." ), sigc::mem_fun( *this, &BoardViewBase::slot_preferences_article ) );
action_group()->add( Gtk::Action::create( "PreferenceBoard", "PreferenceBoard" ), sigc::mem_fun( *this, &BoardViewBase::show_preference ) );
action_group()->add( Gtk::Action::create( "SaveDat", "SaveDat" ),
sigc::mem_fun( *this, &BoardViewBase::slot_save_dat ) );
action_group()->add( Gtk::Action::create( "SearchNextArticle", ITEM_NAME_NEXTARTICLE ),
sigc::mem_fun( *this, &BoardViewBase::slot_search_next ) );
// その他
action_group()->add( Gtk::Action::create( "Etc_Menu", ITEM_NAME_ETC "(_O)" ) );
ui_manager().reset();
ui_manager() = Gtk::UIManager::create();
ui_manager()->insert_action_group( action_group() );
// 通常 + 複数
const std::string menu_mul =
"<popup name='popup_menu_mul'>"
"<menuitem action='OpenRows'/>"
"<separator/>"
"<menuitem action='RegetRows'/>"
"<separator/>"
"<menuitem action='SetBookMark'/>"
"<menuitem action='UnsetBookMark'/>"
"<separator/>"
"<menuitem action='SaveDat'/>"
"<separator/>"
"<menuitem action='Favorite_Article'/>"
"<separator/>"
"<menuitem action='AboneThread'/>"
"<separator/>"
"<menu action='Delete_Menu'>"
"<menuitem action='Delete'/>"
"</menu>"
"</popup>";
// お気に入りボタン押した時のメニュー
const std::string menu_favorite =
"<popup name='popup_menu_favorite'>"
"<menuitem action='Favorite_Article'/>"
"<menuitem action='Favorite_Board'/>"
"</popup>";
// お気に入りボタン押した時のメニュー( スレのみ )
const std::string menu_favorite_article =
"<popup name='popup_menu_favorite_article'>"
"<menuitem action='Favorite_Article'/>"
"</popup>";
// 削除ボタン押した時のメニュー
const std::string menu_delete =
"<popup name='popup_menu_delete'>"
"<menuitem action='Delete'/>"
"</popup>";
ui_manager()->add_ui_from_string(
"<ui>"
+ menu_mul
+ menu_favorite
+ menu_favorite_article
+ menu_delete
+ create_context_menu()
+ "</ui>"
);
// ポップアップメニューにキーアクセレータを表示
Gtk::Menu* popupmenu = dynamic_cast< Gtk::Menu* >( ui_manager()->get_widget( "/popup_menu" ) );
CONTROL::set_menu_motion( popupmenu );
popupmenu = dynamic_cast< Gtk::Menu* >( ui_manager()->get_widget( "/popup_menu_mul" ) );
CONTROL::set_menu_motion( popupmenu );
}
//
// 通常の右クリックメニューの作成
//
std::string BoardViewBase::create_context_menu()
{
std::list< int > list_menu;
list_menu.push_back( ITEM_BOOKMARK );
list_menu.push_back( ITEM_OPENARTICLETAB );
list_menu.push_back( ITEM_REGETARTICLE );
list_menu.push_back( ITEM_OPEN_BROWSER );
list_menu.push_back( ITEM_COPY_URL );
list_menu.push_back( ITEM_COPY_TITLE_URL_THREAD );
list_menu.push_back( ITEM_SAVE_DAT );
list_menu.push_back( ITEM_FAVORITE_ARTICLE );
list_menu.push_back( ITEM_NEXTARTICLE );
list_menu.push_back( ITEM_ABONE_ARTICLE );
list_menu.push_back( ITEM_DELETE );
list_menu.push_back( ITEM_PREF_THREAD );
list_menu.push_back( ITEM_PREF_BOARD );
// メニューに含まれていない項目を抜き出して「その他」に含める
int num = 0;
for(;;){
const int item = SESSION::get_item_board_menu( num );
if( item == ITEM_END ) break;
list_menu.remove( item );
++num;
}
std::string menu;
num = 0;
for(;;){
const int item = SESSION::get_item_board_menu( num );
if( item == ITEM_END ) break;
else if( item == ITEM_ETC && list_menu.size() ){
menu += std::string( "<menu action='Etc_Menu'>" );
std::list< int >::iterator it = list_menu.begin();
for( ; it != list_menu.end(); ++it ) menu += get_menu_item( *it );
menu += std::string( "</menu>" );
}
else menu += get_menu_item( item );
++num;
}
#ifdef _DEBUG
std::cout << "menu = " << menu << std::endl;
#endif
return "<popup name='popup_menu'>" + menu + "</popup>";
}
const char* BoardViewBase::get_menu_item( const int item )
{
switch( item ){
// しおりを設定/解除
case ITEM_BOOKMARK:
return "<menuitem action='BookMark'/>";
// タブでスレを開く
case ITEM_OPENARTICLETAB:
return "<menuitem action='OpenTab'/>";
// スレ情報を消さずに再取得"
case ITEM_REGETARTICLE:
return "<menuitem action='RegetArticle'/>";
// リンクをブラウザで開く
case ITEM_OPEN_BROWSER:
return "<menuitem action='OpenBrowser'/>";
// リンクのURLをコピー
case ITEM_COPY_URL:
return "<menuitem action='CopyURL'/>";
// スレのタイトルとURLをコピー
case ITEM_COPY_TITLE_URL_THREAD:
return "<menuitem action='CopyTitleURL'/>";
// dat 保存
case ITEM_SAVE_DAT:
return "<menuitem action='SaveDat'/>";
// スレをお気に入りに追加
case ITEM_FAVORITE_ARTICLE:
return "<menuitem action='Favorite_Article'/>";
// 次スレ検索
case ITEM_NEXTARTICLE:
return "<menuitem action='SearchNextArticle'/>";
// スレをあぼ〜んする"
case ITEM_ABONE_ARTICLE:
return "<menuitem action='AboneThread'/>";
// 削除
case ITEM_DELETE:
return
"<menu action='Delete_Menu'>"
"<menuitem action='Delete'/>"
"</menu>";
// スレのプロパティ
case ITEM_PREF_THREAD:
return "<menuitem action='PreferenceArticle'/>";
// 板のプロパティ
case ITEM_PREF_BOARD:
return "<menuitem action='PreferenceBoard'/>";
// 区切り
case ITEM_SEPARATOR:
return "<separator/>";
}
return "";
}
//
// 行数
//
int BoardViewBase::get_row_size()
{
return m_treeview.get_row_size();
}
//
// 自動ソート抑制
// -2 = DEFAULT_UNSORTED_COLUMN_ID
//
// 追加や更新などで列に値をセットする前に実行してしておかないと
// いちいちソートをかけるので極端に遅くなる
//
void BoardViewBase::unsorted_column()
{
m_liststore->set_sort_column( Gtk::TreeSortable::DEFAULT_UNSORTED_COLUMN_ID,
Gtk::SortType::SORT_ASCENDING );
}
//
// url から row を取得
//
Gtk::TreeModel::Row BoardViewBase::get_row_from_url( const std::string& url )
{
Gtk::TreeModel::Children child = m_liststore->children();
Gtk::TreeModel::Children::iterator it;
for( it = child.begin() ; it != child.end() ; ++it ){
Gtk::TreeModel::Row row = *( it );
DBTREE::ArticleBase *art = row[ m_columns.m_col_article ];
if( url == art->get_url() ) return row;
}
return Gtk::TreeModel::Row();
}
//
// 列項目の更新
//
void BoardViewBase::update_columns()
{
m_treeview.remove_all_columns();
DELETE_COLUMN( m_col_id );
DELETE_COLUMN( m_col_board );
DELETE_COLUMN( m_col_subject );
DELETE_COLUMN( m_col_res );
DELETE_COLUMN( m_col_str_load );
DELETE_COLUMN( m_col_str_new );
DELETE_COLUMN( m_col_since );
DELETE_COLUMN( m_col_write );
DELETE_COLUMN( m_col_speed );
DELETE_COLUMN( m_col_diff );
DELETE_COLUMN( m_col_access );
int num = 0;
// 先頭に「板」列を追加
if( m_show_col_board ){
bool append_board = true;
for(;;){
const int item = SESSION::get_item_board_col( num );
if( item == ITEM_BOARD ) append_board = false;
if( item == ITEM_END ) break;
num++;
}
if( append_board ) APPEND_COLUMN( m_col_board, ITEM_NAME_BOARD, m_columns.m_col_board );
}
m_col_diff_is_shown = false;
num = 0;
for(;;){
const int item = SESSION::get_item_board_col( num );
if( item == ITEM_END ) break;
switch( item ){
case ITEM_MARK: APPEND_COLUMN( m_col_mark, ITEM_NAME_MARK, m_columns.m_col_mark ); break;
case ITEM_ID: APPEND_COLUMN( m_col_id, ITEM_NAME_ID, m_columns.m_col_id ); break;
case ITEM_BOARD: APPEND_COLUMN( m_col_board, ITEM_NAME_BOARD, m_columns.m_col_board ); break;
case ITEM_NAME: APPEND_COLUMN( m_col_subject, ITEM_NAME_NAME, m_columns.m_col_subject ); break;
case ITEM_RES: APPEND_COLUMN( m_col_res, ITEM_NAME_RES, m_columns.m_col_res ); break;
case ITEM_LOAD: APPEND_COLUMN( m_col_str_load, ITEM_NAME_LOAD, m_columns.m_col_str_load ); break;
case ITEM_NEW: APPEND_COLUMN( m_col_str_new, ITEM_NAME_NEW, m_columns.m_col_str_new ); break;
case ITEM_SINCE: APPEND_COLUMN( m_col_since, ITEM_NAME_SINCE, m_columns.m_col_since ); break;
case ITEM_LASTWRITE: APPEND_COLUMN( m_col_write, ITEM_NAME_LASTWRITE, m_columns.m_col_write ); break;
case ITEM_ACCESS: APPEND_COLUMN( m_col_access, ITEM_NAME_ACCESS, m_columns.m_col_access); break;
case ITEM_SPEED: APPEND_COLUMN( m_col_speed, ITEM_NAME_SPEED, m_columns.m_col_speed ); break;
case ITEM_DIFF: APPEND_COLUMN( m_col_diff, ITEM_NAME_DIFF, m_columns.m_col_diff); m_col_diff_is_shown = true; break;
}
++num;
}
// サイズを調整しつつソートの設定
for( guint i = 0; i < COL_VISIBLE_END; i++ ){
const int id = get_title_id( i );
if( id < 0 ) continue;
Gtk::TreeView::Column* column = m_treeview.get_column( i );
if( ! column ) continue;
int width = 0;
switch( id ){
case COL_MARK:
width = SESSION::col_mark();
break;
case COL_ID:
width = SESSION::col_id();
break;
case COL_BOARD:
width = SESSION::col_board();
break;
case COL_SUBJECT:
width = SESSION::col_subject();
m_treeview.set_column_for_height( id );
break;
case COL_RES:
width = SESSION::col_number();
break;
case COL_STR_LOAD:
width = SESSION::col_load();
break;
case COL_STR_NEW:
width = SESSION::col_new();
break;
case COL_SINCE:
width = SESSION::col_since();
break;
case COL_WRITE:
width = SESSION::col_write();
break;
case COL_ACCESS:
width = SESSION::col_access();
break;
case COL_SPEED:
width = SESSION::col_speed();
break;
case COL_DIFF:
width = SESSION::col_diff();
break;
}
if( ! width ) width = DEFAULT_COLMUN_WIDTH;
column->set_fixed_width( width );
column->set_resizable( true );
column->set_clickable( true );
// ヘッダをクリックしたときに呼ぶslot
column->signal_clicked().connect( sigc::bind< int >( sigc::mem_fun( *this, &BoardViewBase::slot_col_clicked ), id ) );
#if GTKMM_CHECK_VERSION(3,0,0)
// 列の幅が変わったらセッション情報に記憶する
column->connect_property_changed( "width", [this]{ save_column_width(); } );
#endif
// ヘッダの位置
switch( id ){
case COL_MARK:
column->set_alignment( 0.5 );
break;
case COL_ID:
case COL_RES:
case COL_STR_LOAD:
case COL_STR_NEW:
case COL_SPEED:
case COL_DIFF:
column->set_alignment( 1.0 );
break;
default:
column->set_alignment( 0.0 );
break;
}
Gtk::CellRenderer *cell = column->get_first_cell();
// 実際の描画の際に cellrendere のプロパティをセットするスロット関数
if( cell ) column->set_cell_data_func( *cell, sigc::mem_fun( *this, &BoardViewBase::slot_cell_data ) );
Gtk::CellRendererText* rentext = dynamic_cast< Gtk::CellRendererText* >( cell );
if( rentext ){
// 列間スペース
rentext->property_xpad() = 4;
// 行間スペース
rentext->property_ypad() = CONFIG::get_tree_ypad();;
// 文字位置
switch( id ){
case COL_ID:
case COL_RES:
case COL_STR_LOAD:
case COL_STR_NEW:
case COL_SPEED:
case COL_DIFF:
rentext->property_xalign() = 1.0;
break;
default:
rentext->property_xalign() = 0.0;
}
}
}
}
//
// i列目のIDを取得
//
// 失敗の時は-1を変えす
//
int BoardViewBase::get_title_id( const int col )
{
Gtk::TreeView::Column* column = m_treeview.get_column( col );
if( ! column ) return -1;
const std::string title = column->get_title();
int id = -1;
if( title == ITEM_NAME_MARK ) id = COL_MARK;
else if( title == ITEM_NAME_ID ) id = COL_ID;
else if( title == ITEM_NAME_BOARD ) id = COL_BOARD;
else if( title == ITEM_NAME_NAME ) id = COL_SUBJECT;
else if( title == ITEM_NAME_RES ) id = COL_RES;
else if( title == ITEM_NAME_LOAD ) id = COL_STR_LOAD;
else if( title == ITEM_NAME_NEW ) id = COL_STR_NEW;
else if( title == ITEM_NAME_SINCE ) id = COL_SINCE;
else if( title == ITEM_NAME_LASTWRITE ) id = COL_WRITE;
else if( title == ITEM_NAME_ACCESS ) id = COL_ACCESS;
else if( title == ITEM_NAME_SPEED ) id = COL_SPEED;
else if( title == ITEM_NAME_DIFF ) id = COL_DIFF;
return id;
}
//
// ソート列やソートモードの保存
//
void BoardViewBase::save_sort_columns()
{
#ifdef _DEBUG
std::cout << "BoardViewBase::save_sort_columns : url = " << get_url() << std::endl;
#endif
DBTREE::board_set_view_sort_column( get_url_board(), m_col );
DBTREE::board_set_view_sort_mode( get_url_board(), m_sortmode );
DBTREE::board_set_view_sort_pre_column( get_url_board(), m_previous_col );
DBTREE::board_set_view_sort_pre_mode( get_url_board(), m_previous_sortmode );
}
//
// 列の幅の保存
//
void BoardViewBase::save_column_width()
{
#ifdef _DEBUG
std::cout << "save_column_width " << get_url() << std::endl;
#endif
for( guint i = 0; i < COL_VISIBLE_END; i++ ){
const int id = get_title_id( i );
if( id < 0 ) continue;
Gtk::TreeView::Column* column = m_treeview.get_column( i );
int width = 0;
if( column ) width = column->get_width();
if( ! width ) continue;
switch( id ){
case COL_MARK:
SESSION::set_col_mark( width );
break;
case COL_ID:
SESSION::set_col_id( width );
break;
case COL_BOARD:
SESSION::set_col_board( width );
break;
case COL_SUBJECT:
SESSION::set_col_subject( width );
break;
case COL_RES:
SESSION::set_col_number( width );
break;
case COL_STR_LOAD:
SESSION::set_col_load( width );
break;
case COL_STR_NEW:
SESSION::set_col_new( width );
break;
case COL_SINCE:
SESSION::set_col_since( width );
break;
case COL_WRITE:
SESSION::set_col_write( width );
break;
case COL_ACCESS:
SESSION::set_col_access( width );
break;
case COL_SPEED:
SESSION::set_col_speed( width );
break;
case COL_DIFF:
SESSION::set_col_diff( width );
break;
}
}
}
//
// 実際の描画の際に cellrendere のプロパティをセットするスロット関数
//
void BoardViewBase::slot_cell_data( Gtk::CellRenderer* cell, const Gtk::TreeModel::iterator& it )
{
Gtk::TreeModel::Row row = *it;
Gtk::TreePath path = GET_PATH( row );
#ifdef _DEBUG
// std::cout << "BoardViewBase::slot_cell_data path = " << path.to_string() << std::endl;
#endif
// ハイライト色 ( 抽出状態 )
if( row[ m_columns.m_col_drawbg ] ){
cell->property_cell_background() = CONFIG::get_color( COLOR_BACK_HIGHLIGHT_TREE );
cell->property_cell_background_set() = true;
}
else m_treeview.slot_cell_data( cell, it );
}
//
// ソート実行
//
void BoardViewBase::exec_sort()
{
#ifdef _DEBUG
std::cout << "BoardViewBase::exec_sort url = " << get_url() << std::endl;
#endif
if( m_col < 0 || m_col >= COL_VISIBLE_END ){
m_col = COL_ID;
m_sortmode = SORTMODE_ASCEND;
}
m_liststore->set_sort_column( -2, Gtk::SORT_ASCENDING );
m_liststore->set_sort_column( m_col, Gtk::SORT_ASCENDING );
}
//
// ソート状態回復
//
void BoardViewBase::restore_sort()
{
m_search_invert = false;
m_col = get_default_sort_column();
m_sortmode = get_default_view_sort_mode();
m_previous_col = get_default_view_sort_pre_column();
m_previous_sortmode = get_default_view_sort_pre_mode();
if( get_row_size() ){
exec_sort();
goto_top();
}
}
//
// デフォルトのソート状態
//
int BoardViewBase::get_default_sort_column()
{
return DBTREE::board_view_sort_column( get_url_board() );
}
int BoardViewBase::get_default_view_sort_mode()
{
return DBTREE::board_view_sort_mode( get_url_board() );
}
int BoardViewBase::get_default_view_sort_pre_column()
{
return DBTREE::board_view_sort_pre_column( get_url_board() );
}
int BoardViewBase::get_default_view_sort_pre_mode()
{
return DBTREE::board_view_sort_pre_mode( get_url_board() );
}
//
// ヘッダをクリックしたときのslot関数
//
void BoardViewBase::slot_col_clicked( const int col )
{
#ifdef _DEBUG
std::cout << "BoardViewBase::slot_col_clicked col = " << col << std::endl;
#endif
if( m_col != col ){ // 前回クリックした列と違う列をクリックした
m_previous_col = m_col;
m_previous_sortmode = m_sortmode;
m_col = col;
if( m_col == COL_MARK ) m_sortmode = SORTMODE_MARK1;
else if( m_col == COL_ID ) m_sortmode = SORTMODE_ASCEND;
else if( m_col == COL_SUBJECT ) m_sortmode = SORTMODE_ASCEND;
else m_sortmode = SORTMODE_DESCEND;
}
else if( m_sortmode == SORTMODE_DESCEND ) m_sortmode = SORTMODE_ASCEND;
else if( m_sortmode == SORTMODE_ASCEND ) m_sortmode = SORTMODE_DESCEND;
else if( m_sortmode == SORTMODE_MARK1 ) m_sortmode = SORTMODE_MARK2;
else if( m_sortmode == SORTMODE_MARK2 ) m_sortmode = SORTMODE_MARK3;
else if( m_sortmode == SORTMODE_MARK3 ) m_sortmode = SORTMODE_MARK4;
else if( m_sortmode == SORTMODE_MARK4 ) m_sortmode = SORTMODE_MARK1;
if( m_col == COL_MARK ){
std::string info;
if( m_sortmode == SORTMODE_MARK1 ) info = "モード 1";
if( m_sortmode == SORTMODE_MARK2 ) info = "モード 2";
if( m_sortmode == SORTMODE_MARK3 ) info = "モード 3";
if( m_sortmode == SORTMODE_MARK4 ) info = "モード 4";
CORE::core_set_command( "set_info", "", info );
}
/* そろそろ消しても良い? 問題があれば戻す
// 旧バージョンとの互換性のため
if( m_col == COL_MARK ){
if( m_sortmode == SORTMODE_DESCEND || m_sortmode == SORTMODE_ASCEND ) m_sortmode = SORTMODE_MARK1;
}
*/
save_sort_columns();
exec_sort();
focus_view();
}
//
// 抽出状態で比較
//
// row_a が上か row_b が上かを返す。同じ状態なら 0
//
int BoardViewBase::compare_drawbg( Gtk::TreeModel::Row& row_a, Gtk::TreeModel::Row& row_b )
{
const bool draw_a = row_a[ m_columns.m_col_drawbg ];
const bool draw_b = row_b[ m_columns.m_col_drawbg ];
if( draw_a && ! draw_b ) return COL_A_UP;
else if( draw_b && ! draw_a ) return COL_B_UP;
return 0;
}
//
// 列の値によるソート
//
// row_a が上か row_b が上かを返す。同じなら 0
//
int BoardViewBase::compare_col( const int col, const int sortmode, Gtk::TreeModel::Row& row_a, Gtk::TreeModel::Row& row_b )
{
int num_a = 0, num_b = 0;
int ret = 0;
DBTREE::ArticleBase *arta, *artb;