OSDN Git Service

Correct SQL due to database being split apart.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / SavedSearchEdit.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.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;
31
32 public class SavedSearchEdit extends QDialog {
33         private boolean                 okPressed;
34         private final QLineEdit searchName;
35         private final QLineEdit query;
36         QPushButton                     ok;
37         List<SavedSearch>               currentSearches;
38         private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
39         
40         // Constructor
41         public SavedSearchEdit() {
42                 okPressed = false;
43                 setWindowTitle(tr("Add a search"));
44                 setWindowIcon(new QIcon(iconPath+"search.png"));
45                 QGridLayout grid = new QGridLayout();
46                 setLayout(grid);
47                 
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);
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                 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);
69         }
70         
71         // The OK button was pressed
72         @SuppressWarnings("unused")
73         private void okButtonPressed() {
74                 okPressed = true;
75                 close();
76         }
77         
78         // The CANCEL button was pressed
79         @SuppressWarnings("unused")
80         private void cancelButtonPressed() {
81                 okPressed = false;
82                 close();
83         }
84         
85         // Get the name from the field
86         public String getName() {
87                 return searchName.text().trim();
88         }
89         
90         // Set the tag name
91         public void setName(String name) {
92                 searchName.setText(name);
93         }
94         // get the query
95         public String getQuery() {
96                 return query.text().trim();
97         }
98         // Set the query
99         public void setQuery(String q) {
100                 query.setText(q);
101         }
102         // Check if the OK button was pressed
103         public boolean okPressed() {
104                 return okPressed;
105         }
106         
107         // Set the window title
108         public void setTitle(String s) {
109                 setWindowTitle(s);
110         }
111         // List of existing tags
112         public void setSearchList(List<SavedSearch> t) {
113                 currentSearches = t;
114         }
115         // Watch what text is being entered
116         @SuppressWarnings("unused")
117         private void textChanged() {
118                 if (searchName.text().trim().equals("")) {
119                         ok.setEnabled(false);
120                         return;
121                 }
122                 if (currentSearches == null) {
123                         ok.setEnabled(false);
124                         return;
125                 }
126                 if (query.text().trim().equals("")) {
127                         ok.setEnabled(false);
128                         return;
129                 }
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);
134                                 return;
135                         }
136                 } */
137                 ok.setEnabled(true);
138         }
139         // Watch what text is being entered
140 }