2 * This file is part of NeverNote
\r
3 * Copyright 2009 Randy Baumgarte
\r
5 * This file may be licensed under the terms of of the
\r
6 * GNU General Public License Version 2 (the ``GPL'').
\r
8 * Software distributed under the License is distributed
\r
9 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
\r
10 * express or implied. See the GPL for the specific language
\r
11 * governing rights and limitations.
\r
13 * You should have received a copy of the GPL along with this
\r
14 * program. If not, go to http://www.gnu.org/licenses/gpl.html
\r
15 * or write to the Free Software Foundation, Inc.,
\r
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
20 package cx.fbn.nevernote.dialog;
\r
22 //**********************************************
\r
23 //**********************************************
\r
24 //* dialog box used to add a watched folder
\r
25 //**********************************************
\r
26 //**********************************************
\r
28 import java.util.List;
\r
30 import com.evernote.edam.type.Notebook;
\r
31 import com.trolltech.qt.gui.QComboBox;
\r
32 import com.trolltech.qt.gui.QDialog;
\r
33 import com.trolltech.qt.gui.QFileDialog;
\r
34 import com.trolltech.qt.gui.QFileDialog.FileMode;
\r
35 import com.trolltech.qt.gui.QGridLayout;
\r
36 import com.trolltech.qt.gui.QHBoxLayout;
\r
37 import com.trolltech.qt.gui.QIcon;
\r
38 import com.trolltech.qt.gui.QLabel;
\r
39 import com.trolltech.qt.gui.QPushButton;
\r
40 import com.trolltech.qt.gui.QVBoxLayout;
\r
42 import cx.fbn.nevernote.sql.WatchFolderRecord;
\r
44 public class WatchFolderAdd extends QDialog {
\r
45 private final QPushButton okButton;
\r
46 private final QPushButton cancelButton;
\r
47 private boolean okClicked;
\r
48 private final List<Notebook> notebooks;
\r
49 private final WatchFolderRecord record;
\r
50 public final QLabel directory;
\r
51 public final QComboBox keep;
\r
52 public final QComboBox books;
\r
53 private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
\r
55 public WatchFolderAdd(WatchFolderRecord w, List<Notebook> n) {
\r
56 setWindowIcon(new QIcon(iconPath+"folder.png"));
\r
61 okButton = new QPushButton();
\r
62 okButton.setText(tr("OK"));
\r
63 okButton.pressed.connect(this, "onClicked()");
\r
65 cancelButton = new QPushButton();
\r
66 cancelButton.setText(tr("Cancel"));
\r
67 cancelButton.pressed.connect(this, "onCancel()");
\r
69 QPushButton folderButton = new QPushButton();
\r
70 folderButton.setText(tr("Directory"));
\r
71 folderButton.clicked.connect(this, "folderButtonClicked()");
\r
73 directory = new QLabel();
\r
75 directory.setText(record.folder);
\r
77 directory.setText(System.getProperty("user.home"));
\r
79 keep = new QComboBox();
\r
80 keep.addItem(tr("Keep"),"Keep");
\r
81 keep.addItem(tr("Delete"),"Delete");
\r
82 if (record != null) {
\r
84 keep.setCurrentIndex(0);
\r
86 keep.setCurrentIndex(1);
\r
89 books = new QComboBox();
\r
90 for (int i=0; i<notebooks.size(); i++) {
\r
91 books.addItem(notebooks.get(i).getName());
\r
92 if (record != null) {
\r
93 if (record.notebook.equals(notebooks.get(i).getName()))
\r
94 books.setCurrentIndex(i);
\r
98 QGridLayout grid = new QGridLayout();
\r
99 grid.addWidget(directory,0,1);
\r
100 grid.addWidget(folderButton,0,0);
\r
101 grid.addWidget(new QLabel(tr("Notebook")),1,0);
\r
102 grid.addWidget(books,1,1);
\r
103 grid.addWidget(new QLabel(tr("After Import")), 2,0);
\r
104 grid.addWidget(keep,2,1);
\r
106 QHBoxLayout buttonLayout = new QHBoxLayout();
\r
107 buttonLayout.addStretch(1);
\r
108 buttonLayout.addWidget(okButton);
\r
109 buttonLayout.addWidget(cancelButton);
\r
110 setWindowTitle(tr("Add Import Folder"));
\r
113 QVBoxLayout mainLayout = new QVBoxLayout();
\r
114 mainLayout.addLayout(grid);
\r
115 mainLayout.addSpacing(1);
\r
116 mainLayout.addLayout(buttonLayout);
\r
117 setLayout(mainLayout);
\r
121 @SuppressWarnings("unused")
\r
122 private void onClicked() {
\r
127 @SuppressWarnings("unused")
\r
128 private void onCancel() {
\r
133 public boolean okClicked() {
\r
137 @SuppressWarnings("unused")
\r
138 private void itemSelected() {
\r
139 okButton.setEnabled(true);
\r
142 @SuppressWarnings("unused")
\r
143 private void folderButtonClicked() {
\r
144 QFileDialog fileDialog = new QFileDialog();
\r
145 fileDialog.setFileMode(FileMode.DirectoryOnly);
\r
146 fileDialog.fileSelected.connect(this, "folderSelected(String)");
\r
150 @SuppressWarnings("unused")
\r
151 private void folderSelected(String f) {
\r
152 String whichOS = System.getProperty("os.name");
\r
153 if (whichOS.contains("Windows"))
\r
154 f = f.replace('/','\\');
\r
155 directory.setText(f);
\r