OSDN Git Service

操作ログの収集を一時停止するボタンを追加した
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / gui / RensoNoteListDock.java
1 /*
2  * This file is part of NeighborNote
3  * Copyright 2013 Yuki Takahashi
4  * 
5  * This file may be licensed under the terms of of the
6  * GNU General Public License Version 2 (the ``GPL'').
7  *
8  * Software distributed under the License is distributed
9  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
10  * express or implied. See the GPL for the specific language
11  * governing rights and limitations.
12  *
13  * You should have received a copy of the GPL along with this
14  * program. If not, go to http://www.gnu.org/licenses/gpl.html
15  * or write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18 */
19
20 package cx.fbn.nevernote.gui;
21
22 import com.trolltech.qt.core.QSize;
23 import com.trolltech.qt.gui.QDockWidget;
24 import com.trolltech.qt.gui.QIcon;
25 import com.trolltech.qt.gui.QMessageBox;
26 import com.trolltech.qt.gui.QPushButton;
27 import com.trolltech.qt.gui.QSizePolicy;
28 import com.trolltech.qt.gui.QToolBar;
29 import com.trolltech.qt.gui.QVBoxLayout;
30 import com.trolltech.qt.gui.QWidget;
31
32 import cx.fbn.nevernote.Global;
33 import cx.fbn.nevernote.NeverNote;
34 import cx.fbn.nevernote.sql.DatabaseConnection;
35 import cx.fbn.nevernote.threads.SyncRunner;
36 import cx.fbn.nevernote.utilities.ApplicationLogger;
37
38 public class RensoNoteListDock extends QDockWidget {
39         private final DatabaseConnection        conn;
40         private final NeverNote                         parent;
41         private final SyncRunner                        syncRunner;
42         private final ApplicationLogger         logger;
43         private final QPushButton                       haltLogButton;                  // 操作ログの取得を停止ボタン
44         private final RensoNoteList                     rensoNoteList;                  // 連想ノートリスト
45         private final QToolBar                          rensoToolBar;                   // 連想ノートリストドックのツールバー
46         
47         private final String                            iconPath;
48         
49         public RensoNoteListDock(DatabaseConnection conn, NeverNote parent, SyncRunner syncRunner, String iconPath, String title) {
50                 super(title);
51                 
52                 this.logger = new ApplicationLogger("rensoNoteList.log");
53                 this.logger.log(this.logger.HIGH, "Setting up rensoNoteListDock");
54                 
55                 this.conn = conn;
56                 this.parent = parent;
57                 this.iconPath = iconPath;
58                 this.syncRunner = syncRunner;
59                 
60                 QVBoxLayout vLayout = new QVBoxLayout();
61                 rensoToolBar = new QToolBar();
62                 vLayout.addWidget(rensoToolBar);
63                 
64                 haltLogButton = new QPushButton();
65                 QIcon haltLogIcon = new QIcon(this.iconPath + "haltLog.png");
66                 haltLogButton.setIcon(haltLogIcon);
67                 haltLogButton.setIconSize(new QSize(24, 24));
68                 haltLogButton.setToolTip(tr("Halt Collectiong Operation Log"));
69                 haltLogButton.setCheckable(true);
70                 haltLogButton.setChecked(Global.isHaltLogButton());
71                 haltLogButton.toggled.connect(this, "haltLogToggled(boolean)");
72                 
73                 // ログ取得停止ボタンを右寄せするためのスペーサ
74                 QWidget spacer = new QWidget();
75                 spacer.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding);
76                 rensoToolBar.addWidget(spacer);
77                 rensoToolBar.addWidget(haltLogButton);
78                 
79                 rensoNoteList = new RensoNoteList(this.conn, this.parent, this.syncRunner, this.logger);
80                 getRensoNoteList().itemPressed.connect(this.parent, "rensoNoteItemPressed(QListWidgetItem)");
81                 vLayout.addWidget(getRensoNoteList());
82
83                 QWidget w = new QWidget();
84                 w.setLayout(vLayout);
85                 this.setWidget(w);
86         }
87         
88         @SuppressWarnings("unused")
89         private void haltLogToggled(boolean checked) {
90                 logger.log(logger.EXTREME, "RensoNoteListDock.haltLogToggled");
91                 
92                 if (checked) {
93                         QMessageBox.information(this, tr("Halt Collectiong Operation Log"), tr("Collecting operation log halted.\nYou can resume, if you press this button again."));
94                 }
95                 Global.saveHaltLogButton(checked);
96         }
97
98         public RensoNoteList getRensoNoteList() {
99                 return rensoNoteList;
100         }
101 }