OSDN Git Service

Add experimental http proxy support
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / NotebookEdit.java
1 /*
2  * This file is part of NeverNote 
3  * Copyright 2009 Randy Baumgarte
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.dialog;
21
22 import java.util.List;
23
24 import com.evernote.edam.type.Notebook;
25 import com.trolltech.qt.gui.QCheckBox;
26 import com.trolltech.qt.gui.QDialog;
27 import com.trolltech.qt.gui.QGridLayout;
28 import com.trolltech.qt.gui.QLabel;
29 import com.trolltech.qt.gui.QLineEdit;
30 import com.trolltech.qt.gui.QPushButton;
31
32 public class NotebookEdit extends QDialog {
33         private boolean                 okPressed;
34         private final QLineEdit         notebook;
35         private final QCheckBox         localRemote;
36         private final QPushButton               ok;
37         private List<Notebook>  currentNotebooks;
38                 
39         // Constructor
40         public NotebookEdit() {
41                 okPressed = false;
42                 setWindowTitle(tr("Add Notebook"));
43                 QGridLayout grid = new QGridLayout();
44                 setLayout(grid);
45                 
46                 QGridLayout textLayout = new QGridLayout();
47                 notebook = new QLineEdit();
48                 textLayout.addWidget(new QLabel(tr("Notebook Name")), 1,1);
49                 textLayout.addWidget(notebook, 1, 2);
50                 textLayout.setContentsMargins(10, 10,-10, -10);
51                 grid.addLayout(textLayout,1,1);
52                 
53                 localRemote = new QCheckBox();
54                 localRemote.setText(tr("Local Notebook"));
55                 localRemote.setChecked(false);
56                 grid.addWidget(localRemote, 2,1);
57                 
58                 QGridLayout buttonLayout = new QGridLayout();
59                 ok = new QPushButton(tr("OK"));
60                 ok.clicked.connect(this, "okButtonPressed()");
61                 ok.setEnabled(false);
62                 QPushButton cancel = new QPushButton(tr("Cancel"));
63                 cancel.clicked.connect(this, "cancelButtonPressed()");
64                 notebook.textChanged.connect(this, "textChanged()");
65                 buttonLayout.addWidget(ok, 1, 1);
66                 buttonLayout.addWidget(cancel, 1,2);
67                 grid.addLayout(buttonLayout,3,1);
68         }
69         
70         // The OK button was pressed
71         @SuppressWarnings("unused")
72         private void okButtonPressed() {
73                 okPressed = true;
74                 close();
75         }
76         
77         // The CANCEL button was pressed
78         @SuppressWarnings("unused")
79         private void cancelButtonPressed() {
80                 okPressed = false;
81                 close();
82         }
83         
84         // Get the userid from the field
85         public String getNotebook() {
86                 return notebook.text();
87         }
88         
89         // Set the notebook name
90         public void setNotebook(String name) {
91                 notebook.setText(name);
92         }
93         
94         // Is this a local notebook?
95         public boolean isLocal() {
96                 return localRemote.isChecked();
97         }
98         
99         // Hide the local/remote checkbox
100         public void setLocalCheckboxEnabled(boolean visible) {
101                 localRemote.setEnabled(visible);
102         }
103         
104         
105         // Check if the OK button was pressed
106         public boolean okPressed() {
107                 return okPressed;
108         }
109         
110         // Set the window title
111         public void setTitle(String s) {
112                 setWindowTitle(s);
113         }
114         
115         // set notebooks 
116         public void setNotebooks(List<Notebook> n) {
117                 currentNotebooks = n;
118         }
119         
120         // Watch what text is being entered
121         @SuppressWarnings("unused")
122         private void textChanged() {
123                 if (notebook.text().equals("")) {
124                         ok.setEnabled(false);
125                         return;
126                 }
127                 if (notebook.text().equalsIgnoreCase("All Notebooks")) {
128                         ok.setEnabled(false);
129                         return;
130                 }
131                 if (currentNotebooks == null) {
132                         ok.setEnabled(false);
133                         return;
134                 }
135                 for (int i=0; i<currentNotebooks.size(); i++) {
136                         String s = currentNotebooks.get(i).getName();
137                         if (s.equalsIgnoreCase(notebook.text())) {
138                                 ok.setEnabled(false);
139                                 return;
140                         }
141                 }
142                 ok.setEnabled(true);
143         }
144 }