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.QIcon;
28 import com.trolltech.qt.gui.QLabel;
29 import com.trolltech.qt.gui.QLineEdit;
30 import com.trolltech.qt.gui.QPushButton;
32 public class SavedSearchEdit extends QDialog {
33 private boolean okPressed;
34 private final QLineEdit searchName;
35 private final QLineEdit query;
37 List<SavedSearch> currentSearches;
38 private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
41 public SavedSearchEdit() {
43 setWindowTitle(tr("Add a search"));
44 setWindowIcon(new QIcon(iconPath+"search.png"));
45 QGridLayout grid = new QGridLayout();
48 QGridLayout textLayout = new QGridLayout();
49 searchName = new QLineEdit();
50 textLayout.addWidget(new QLabel(tr("Name")), 1,1);
51 textLayout.addWidget(searchName, 1, 2);
52 query = new QLineEdit();
53 textLayout.addWidget(new QLabel(tr("String")), 2,1);
54 textLayout.addWidget(query, 2, 2);
55 textLayout.setContentsMargins(10, 10,-10, -10);
56 grid.addLayout(textLayout, 1, 1);
58 QGridLayout buttonLayout = new QGridLayout();
59 ok = new QPushButton(tr("OK"));
60 ok.clicked.connect(this, "okButtonPressed()");
62 QPushButton cancel = new QPushButton(tr("Cancel"));
63 cancel.clicked.connect(this, "cancelButtonPressed()");
64 searchName.textChanged.connect(this, "textChanged()");
65 query.textChanged.connect(this, "textChanged()");
66 buttonLayout.addWidget(ok, 1, 1);
67 buttonLayout.addWidget(cancel, 1,2);
68 grid.addLayout(buttonLayout,2,1);
71 // The OK button was pressed
72 @SuppressWarnings("unused")
73 private void okButtonPressed() {
78 // The CANCEL button was pressed
79 @SuppressWarnings("unused")
80 private void cancelButtonPressed() {
85 // Get the name from the field
86 public String getName() {
87 return searchName.text().trim();
91 public void setName(String name) {
92 searchName.setText(name);
95 public String getQuery() {
96 return query.text().trim();
99 public void setQuery(String q) {
102 // Check if the OK button was pressed
103 public boolean okPressed() {
107 // Set the window title
108 public void setTitle(String s) {
111 // List of existing tags
112 public void setSearchList(List<SavedSearch> t) {
115 // Watch what text is being entered
116 @SuppressWarnings("unused")
117 private void textChanged() {
118 if (searchName.text().trim().equals("")) {
119 ok.setEnabled(false);
122 if (currentSearches == null) {
123 ok.setEnabled(false);
126 if (query.text().trim().equals("")) {
127 ok.setEnabled(false);
130 /* for (int i=0; i<currentSearches.size(); i++) {
131 String s = currentSearches.get(i).getName();
132 if (s.equalsIgnoreCase(searchName.text())) {
133 ok.setEnabled(false);
139 // Watch what text is being entered