2 * This file is part of NeighborNote
3 * Copyright 2013 Yuki Takahashi
5 * This file may be licensed under the terms of of the
6 * GNU General Public License Version 2 (the ``GPL'').
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.
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.
20 package cx.fbn.nevernote.gui;
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.EnumMap;
25 import java.util.List;
28 import com.trolltech.qt.core.QSize;
29 import com.trolltech.qt.gui.QComboBox;
30 import com.trolltech.qt.gui.QDockWidget;
31 import com.trolltech.qt.gui.QIcon;
32 import com.trolltech.qt.gui.QLabel;
33 import com.trolltech.qt.gui.QMessageBox;
34 import com.trolltech.qt.gui.QPushButton;
35 import com.trolltech.qt.gui.QSizePolicy;
36 import com.trolltech.qt.gui.QToolBar;
37 import com.trolltech.qt.gui.QVBoxLayout;
38 import com.trolltech.qt.gui.QWidget;
40 import cx.fbn.nevernote.Global;
41 import cx.fbn.nevernote.NeverNote;
42 import cx.fbn.nevernote.sql.DatabaseConnection;
43 import cx.fbn.nevernote.threads.SyncRunner;
44 import cx.fbn.nevernote.utilities.ApplicationLogger;
46 public class RensoNoteListDock extends QDockWidget {
47 private final DatabaseConnection conn;
48 private final NeverNote parent;
49 private final SyncRunner syncRunner;
50 private final ApplicationLogger logger;
51 private final QPushButton haltLogButton; // 操作ログの取得を停止ボタン
52 private final QComboBox weightingModeSelect; // 連想ノートリストの重み付けプリセットモード
53 private final RensoNoteList rensoNoteList; // 連想ノートリスト
54 private final QToolBar rensoToolBar; // 連想ノートリストドックのツールバー
55 private enum PresetMode {Standard, ConcurrentBrowse, OperationToOrganize, ContentSimilarity, Custom}; // プリセットモード一覧
57 private final String iconPath;
59 public RensoNoteListDock(DatabaseConnection conn, NeverNote parent, SyncRunner syncRunner, String iconPath, String title) {
62 this.logger = new ApplicationLogger("rensoNoteList.log");
63 this.logger.log(this.logger.HIGH, "Setting up rensoNoteListDock");
67 this.iconPath = iconPath;
68 this.syncRunner = syncRunner;
70 QVBoxLayout vLayout = new QVBoxLayout();
71 rensoToolBar = new QToolBar();
72 vLayout.addWidget(rensoToolBar);
74 QLabel modeLabel = new QLabel(tr("Mode: "));
75 modeLabel.setToolTip(tr("Preset Weighting Mode"));
76 rensoToolBar.addWidget(modeLabel);
78 weightingModeSelect = new QComboBox();
79 weightingModeSelect.setMaximumWidth(150);
80 weightingModeSelect.setToolTip(tr("Preset Weighting Mode"));
81 weightingModeSelect.insertItem(PresetMode.Standard.ordinal(), tr("Standard"));
82 weightingModeSelect.insertItem(PresetMode.ConcurrentBrowse.ordinal(), tr("Concurrent Browse"));
83 weightingModeSelect.insertItem(PresetMode.OperationToOrganize.ordinal(), tr("Operation to Organize"));
84 weightingModeSelect.insertItem(PresetMode.ContentSimilarity.ordinal(), tr("Content Similarity"));
85 weightingModeSelect.insertItem(PresetMode.Custom.ordinal(), tr("Custom"));
86 int savedModeIndex = 0;
88 savedModeIndex = PresetMode.valueOf(Global.rensoWeightingSelect()).ordinal();
89 } catch (Exception e) {
90 this.logger.log(this.logger.EXTREME, "Exception in weightingModeSelect = " + e);
92 if (savedModeIndex >= 0) {
93 weightingModeSelect.setCurrentIndex(savedModeIndex);
95 weightingModeSelect.setCurrentIndex(0);
97 weightingModeSelect.currentIndexChanged.connect(this, "weightingModeChanged(int)");
98 rensoToolBar.addWidget(weightingModeSelect);
100 haltLogButton = new QPushButton();
101 QIcon haltLogIcon = new QIcon(this.iconPath + "haltLog.png");
102 haltLogButton.setIcon(haltLogIcon);
103 haltLogButton.setIconSize(new QSize(24, 24));
104 haltLogButton.setToolTip(tr("Halt Collectiong Operation Log"));
105 haltLogButton.setCheckable(true);
106 haltLogButton.setChecked(Global.isHaltLogButton());
107 haltLogButton.toggled.connect(this, "haltLogToggled(boolean)");
109 // ログ取得停止ボタンを右寄せするためのスペーサ
110 QWidget spacer = new QWidget();
111 spacer.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding);
112 rensoToolBar.addWidget(spacer);
113 rensoToolBar.addWidget(haltLogButton);
115 rensoNoteList = new RensoNoteList(this.conn, this.parent, this.syncRunner, this.logger);
116 getRensoNoteList().itemPressed.connect(this.parent, "rensoNoteItemPressed(QListWidgetItem)");
117 vLayout.addWidget(getRensoNoteList());
119 QWidget w = new QWidget();
120 w.setLayout(vLayout);
124 @SuppressWarnings("unused")
125 private void weightingModeChanged(int modeIndex) {
126 logger.log(logger.EXTREME, "RensoNoteListDock.weightingModeChanged modeIndex = " + modeIndex);
128 PresetMode mode = Global.fromOrdinal(PresetMode.class, modeIndex);
131 // 値は同時閲覧、コピペ、新規ノート追加、連想ノートクリック、同じタグ、同じノートブック、Evernote関連ノートの順
132 Map<PresetMode, List<Integer>> presetMap = new EnumMap<PresetMode, List<Integer>>(PresetMode.class);
133 presetMap.put(PresetMode.Standard, Arrays.asList(1, 3, 3, 10, 2, 2, 5));
134 presetMap.put(PresetMode.ConcurrentBrowse, Arrays.asList(5, 2, 3, 10, 1, 1, 2));
135 presetMap.put(PresetMode.OperationToOrganize, Arrays.asList(1, 2, 3, 10, 5, 5, 2));
136 presetMap.put(PresetMode.ContentSimilarity, Arrays.asList(1, 2, 2, 10, 1, 1, 10));
137 presetMap.put(PresetMode.Custom, Arrays.asList(Global.customBrowseWeight(), Global.customCopyPasteWeight(),
138 Global.customAddNewNoteWeight(), Global.customRensoItemClickWeight(), Global.customSameTagWeight(),
139 Global.customSameNotebookWeight(), Global.customENRelatedNotesWeight()));
141 List<Integer> weightList = new ArrayList<Integer>(presetMap.get(mode));
142 Global.setBrowseWeight(weightList.get(0));
143 Global.setCopyPasteWeight(weightList.get(1));
144 Global.setAddNewNoteWeight(weightList.get(2));
145 Global.setRensoItemClickWeight(weightList.get(3));
146 Global.setSameTagWeight(weightList.get(4));
147 Global.setSameNotebookWeight(weightList.get(5));
148 Global.setENRelatedNotesWeight(weightList.get(6));
150 Global.saveRensoWeightingSelect(mode.name());
153 if (rensoNoteList != null && rensoNoteList.getGuid() != null ) {
154 rensoNoteList.refreshRensoNoteList();
156 // カスタムモードかつアプリ起動時以外なら、メッセージ表示
157 if (mode == PresetMode.Custom) {
158 QMessageBox.information(this, tr("Information"), tr("Custom mode was selected.\nYou can customize weighting manually in the Edit/Preferences/Renso Note List."));
163 @SuppressWarnings("unused")
164 private void haltLogToggled(boolean checked) {
165 logger.log(logger.EXTREME, "RensoNoteListDock.haltLogToggled");
168 QMessageBox.information(this, tr("Information"), tr("Collecting operation log halted.\nYou can resume, if you press this button again."));
170 Global.saveHaltLogButton(checked);
173 public RensoNoteList getRensoNoteList() {
174 return rensoNoteList;