import com.trolltech.qt.gui.QCheckBox;
import com.trolltech.qt.gui.QDialog;
import com.trolltech.qt.gui.QGridLayout;
+import com.trolltech.qt.gui.QIcon;
import com.trolltech.qt.gui.QLabel;
import com.trolltech.qt.gui.QLineEdit;
import com.trolltech.qt.gui.QPushButton;
private final QCheckBox localRemote;
private final QPushButton ok;
private List<Notebook> currentNotebooks;
-
+ private final QCheckBox isDefault;
+ private boolean startDefault;
+ private String startText;
+ private List<String> stacks;
+ private boolean stackEdit;
+ private final QLabel notebookLabel;
+ private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
+
// Constructor
public NotebookEdit() {
okPressed = false;
+ stackEdit = false;
setWindowTitle(tr("Add Notebook"));
+ setWindowIcon(new QIcon(iconPath+"notebook-green.png"));
QGridLayout grid = new QGridLayout();
setLayout(grid);
QGridLayout textLayout = new QGridLayout();
notebook = new QLineEdit();
- textLayout.addWidget(new QLabel(tr("Notebook Name")), 1,1);
+ notebookLabel = new QLabel(tr("Notebook Name"));
+ textLayout.addWidget(notebookLabel, 1,1);
textLayout.addWidget(notebook, 1, 2);
textLayout.setContentsMargins(10, 10,-10, -10);
grid.addLayout(textLayout,1,1);
localRemote.setText(tr("Local Notebook"));
localRemote.setChecked(false);
grid.addWidget(localRemote, 2,1);
-
+
+ isDefault = new QCheckBox();
+ isDefault.setText(tr("Default Notebook"));
+ isDefault.setChecked(false);
+ isDefault.toggled.connect(this, "defaultNotebookChecked(Boolean)");
+ grid.addWidget(isDefault, 3,1);
+
QGridLayout buttonLayout = new QGridLayout();
ok = new QPushButton(tr("OK"));
ok.clicked.connect(this, "okButtonPressed()");
notebook.textChanged.connect(this, "textChanged()");
buttonLayout.addWidget(ok, 1, 1);
buttonLayout.addWidget(cancel, 1,2);
- grid.addLayout(buttonLayout,3,1);
+ grid.addLayout(buttonLayout,4,1);
}
// The OK button was pressed
return notebook.text();
}
+ // Set the stack names
+ public void setStacks(List<String> s) {
+ stacks = s;
+ stackEdit = true;
+ notebookLabel.setText(new String(tr("Stack Name")));
+ }
+
// Set the notebook name
public void setNotebook(String name) {
+ if (name.equalsIgnoreCase("All Notebooks")) {
+ notebook.setEnabled(false);
+ localRemote.setEnabled(false);
+ isDefault.setEnabled(false);
+ }
notebook.setText(name);
+ startText = name;
}
// Is this a local notebook?
currentNotebooks = n;
}
+ // Get default notebook
+ public void setDefaultNotebook(boolean val) {
+ startDefault = val;
+ isDefault.setChecked(val);
+ if (val)
+ isDefault.setEnabled(true);
+ }
+ public boolean isDefaultNotebook() {
+ return isDefault.isChecked();
+ }
+
+ // Action when the default notebook icon is checked
+ private void defaultNotebookChecked(Boolean val) {
+ if (val != startDefault || !startText.equals(notebook.text()))
+ ok.setEnabled(true);
+ else
+ ok.setEnabled(false);
+ }
+
+ // Hide checkboxes
+ public void hideDefaultCheckbox() {
+ isDefault.setVisible(false);
+ }
+ public void hideLocalCheckbox() {
+ localRemote.setVisible(false);
+ }
+
// Watch what text is being entered
@SuppressWarnings("unused")
private void textChanged() {
ok.setEnabled(false);
return;
}
- if (currentNotebooks == null) {
- ok.setEnabled(false);
- return;
+ if (stackEdit) {
+ for (int i=0; i<stacks.size(); i++) {
+ if (stacks.get(i).equalsIgnoreCase(notebook.text())) {
+ ok.setEnabled(false);
+ return;
+ }
+ }
}
- for (int i=0; i<currentNotebooks.size(); i++) {
- String s = currentNotebooks.get(i).getName();
- if (s.equalsIgnoreCase(notebook.text())) {
+ if (!stackEdit) {
+ if (currentNotebooks == null) {
ok.setEnabled(false);
return;
}
+ for (int i=0; i<currentNotebooks.size(); i++) {
+ String s = currentNotebooks.get(i).getName();
+ if (s.equalsIgnoreCase(notebook.text())) {
+ ok.setEnabled(false);
+ return;
+ }
+ }
}
ok.setEnabled(true);
}