2 * This file is part of NeverNote
3 * Copyright 2009 Randy Baumgarte
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.dialog;
22 import java.util.List;
24 import com.evernote.edam.type.SavedSearch;
25 import com.trolltech.qt.gui.QDialog;
26 import com.trolltech.qt.gui.QGridLayout;
27 import com.trolltech.qt.gui.QLabel;
28 import com.trolltech.qt.gui.QLineEdit;
29 import com.trolltech.qt.gui.QPushButton;
31 public class SavedSearchEdit extends QDialog {
32 private boolean okPressed;
33 private final QLineEdit searchName;
34 private final QLineEdit query;
36 List<SavedSearch> currentSearches;
40 public SavedSearchEdit() {
42 setWindowTitle("Add a search");
43 QGridLayout grid = new QGridLayout();
46 QGridLayout textLayout = new QGridLayout();
47 searchName = new QLineEdit();
48 textLayout.addWidget(new QLabel("Name"), 1,1);
49 textLayout.addWidget(searchName, 1, 2);
50 query = new QLineEdit();
51 textLayout.addWidget(new QLabel("String"), 2,1);
52 textLayout.addWidget(query, 2, 2);
53 textLayout.setContentsMargins(10, 10,-10, -10);
54 grid.addLayout(textLayout, 1, 1);
56 QGridLayout buttonLayout = new QGridLayout();
57 ok = new QPushButton("OK");
58 ok.clicked.connect(this, "okButtonPressed()");
60 QPushButton cancel = new QPushButton("Cancel");
61 cancel.clicked.connect(this, "cancelButtonPressed()");
62 searchName.textChanged.connect(this, "textChanged()");
63 query.textChanged.connect(this, "textChanged()");
64 buttonLayout.addWidget(ok, 1, 1);
65 buttonLayout.addWidget(cancel, 1,2);
66 grid.addLayout(buttonLayout,2,1);
69 // The OK button was pressed
70 @SuppressWarnings("unused")
71 private void okButtonPressed() {
76 // The CANCEL button was pressed
77 @SuppressWarnings("unused")
78 private void cancelButtonPressed() {
83 // Get the name from the field
84 public String getName() {
85 return searchName.text().trim();
89 public void setName(String name) {
90 searchName.setText(name);
93 public String getQuery() {
94 return query.text().trim();
97 public void setQuery(String q) {
100 // Check if the OK button was pressed
101 public boolean okPressed() {
105 // Set the window title
106 public void setTitle(String s) {
109 // List of existing tags
110 public void setSearchList(List<SavedSearch> t) {
113 // Watch what text is being entered
114 @SuppressWarnings("unused")
115 private void textChanged() {
116 if (searchName.text().trim().equals("")) {
117 ok.setEnabled(false);
120 if (currentSearches == null) {
121 ok.setEnabled(false);
124 if (query.text().trim().equals("")) {
125 ok.setEnabled(false);
128 /* for (int i=0; i<currentSearches.size(); i++) {
129 String s = currentSearches.get(i).getName();
130 if (s.equalsIgnoreCase(searchName.text())) {
131 ok.setEnabled(false);
137 // Watch what text is being entered