import cx.fbn.nevernote.dialog.NotebookEdit;
import cx.fbn.nevernote.dialog.OnlineNoteHistory;
import cx.fbn.nevernote.dialog.SavedSearchEdit;
+import cx.fbn.nevernote.dialog.SetIcon;
import cx.fbn.nevernote.dialog.TagEdit;
import cx.fbn.nevernote.dialog.ThumbnailViewer;
import cx.fbn.nevernote.dialog.WatchFolder;
notebookTree.setDeleteAction(menuBar.notebookDeleteAction);
notebookTree.setEditAction(menuBar.notebookEditAction);
notebookTree.setAddAction(menuBar.notebookAddAction);
+ notebookTree.setIconAction(menuBar.notebookIconAction);
notebookTree.setVisible(Global.isWindowVisible("notebookTree"));
notebookTree.noteSignal.notebookChanged.connect(this, "updateNoteNotebook(String, String)");
menuBar.hideNotebooks.setChecked(Global.isWindowVisible("notebookTree"));
menuBar.noteRestoreAction.setVisible(false);
menuBar.notebookEditAction.setEnabled(true);
menuBar.notebookDeleteAction.setEnabled(true);
+ menuBar.notebookIconAction.setEnabled(true);
List<QTreeWidgetItem> selections = notebookTree.selectedItems();
QTreeWidgetItem currentSelection;
selectedNotebookGUIDs.clear();
selectedNotebookGUIDs.clear();
menuBar.notebookEditAction.setEnabled(false);
menuBar.notebookDeleteAction.setEnabled(false);
+ menuBar.notebookIconAction.setEnabled(false);
}
if (selectedNotebookGUIDs.size() == 1 && selectedNotebookGUIDs.get(0).equals(previousSelectedNotebook)) {
previousSelectedNotebook = selectedNotebookGUIDs.get(0);
String guid = "";
if (selections.size() > 0)
guid = (selections.get(0).text(2));
- if (!guid.equals(""))
+ if (!guid.equals("")) {
selectedNotebookGUIDs.add(guid);
+ menuBar.notebookIconAction.setEnabled(true);
+ }
+ else {
+ menuBar.notebookIconAction.setEnabled(false);
+ }
}
listManager.setSelectedNotebooks(selectedNotebookGUIDs);
listManager.loadNotesIndex();
// Triggered when the notebook DB has been updated
private void notebookIndexUpdated() {
logger.log(logger.HIGH, "Entering NeverNote.notebookIndexUpdated");
- if (selectedNotebookGUIDs == null)
+
+ // Get the possible icons
+ HashMap<String, QIcon> icons = conn.getNotebookTable().getAllIcons();
+ notebookTree.setIcons(icons);
+
+ if (selectedNotebookGUIDs == null)
selectedNotebookGUIDs = new ArrayList<String>();
List<Notebook> books = conn.getNotebookTable().getAll();
for (int i=books.size()-1; i>=0; i--) {
waitCursor(false);
browserWindow.setNotebookList(nbooks);
}
+ // Change the notebook's icon
+ private void setNotebookIcon() {
+ QTreeWidgetItem currentSelection;
+ List<QTreeWidgetItem> selections = notebookTree.selectedItems();
+ if (selections.size() == 0)
+ return;
+
+ currentSelection = selections.get(0);
+ String guid = currentSelection.text(2);
+ if (guid.equalsIgnoreCase(""))
+ return;
+ QIcon currentIcon = currentSelection.icon(0);
+ QIcon icon = conn.getNotebookTable().getIcon(guid);
+ SetIcon dialog;
+ if (icon == null) {
+ dialog = new SetIcon(currentIcon);
+ dialog.setUseDefaultIcon(true);
+ } else {
+ dialog = new SetIcon(icon);
+ dialog.setUseDefaultIcon(false);
+ }
+ dialog.exec();
+ if (dialog.okPressed()) {
+ QIcon newIcon = dialog.getIcon();
+ conn.getNotebookTable().setIcon(guid, newIcon, dialog.getFileType());
+ if (newIcon == null) {
+ boolean isPublished = false;;
+ boolean found = false;
+ for (int i=0; i<listManager.getNotebookIndex().size() && !found; i++) {
+ if (listManager.getNotebookIndex().get(i).getGuid().equals(guid)) {
+ isPublished = listManager.getNotebookIndex().get(i).isPublished();
+ found = true;
+ }
+ }
+ newIcon = notebookTree.findDefaultIcon(guid, currentSelection.text(1), listManager.getLocalNotebooks(), isPublished);
+ }
+ currentSelection.setIcon(0, newIcon);
+ }
-
+ }
//***************************************************************
--- /dev/null
+/*
+ * This file is part of NeverNote
+ * Copyright 2009 Randy Baumgarte
+ *
+ * This file may be licensed under the terms of of the
+ * GNU General Public License Version 2 (the ``GPL'').
+ *
+ * Software distributed under the License is distributed
+ * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
+ * express or implied. See the GPL for the specific language
+ * governing rights and limitations.
+ *
+ * You should have received a copy of the GPL along with this
+ * program. If not, go to http://www.gnu.org/licenses/gpl.html
+ * or write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+*/
+
+package cx.fbn.nevernote.dialog;
+
+import com.trolltech.qt.gui.QCheckBox;
+import com.trolltech.qt.gui.QDialog;
+import com.trolltech.qt.gui.QFileDialog;
+import com.trolltech.qt.gui.QFileDialog.AcceptMode;
+import com.trolltech.qt.gui.QFileDialog.FileMode;
+import com.trolltech.qt.gui.QGridLayout;
+import com.trolltech.qt.gui.QIcon;
+import com.trolltech.qt.gui.QPushButton;
+import com.trolltech.qt.gui.QSizePolicy.Policy;
+
+public class SetIcon extends QDialog {
+ private boolean okPressed;
+ QPushButton ok;
+ QPushButton iconButton;
+ QCheckBox useDefault;
+ QIcon defaultIcon;
+ boolean startUseDefault;
+ private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
+
+ // Constructor
+ public SetIcon(QIcon i) {
+ okPressed = false;
+ setWindowTitle(tr("Set Icon"));
+ QGridLayout grid = new QGridLayout();
+ setWindowIcon(new QIcon(iconPath+"nevernote.png"));
+ setLayout(grid);
+
+ QGridLayout textGrid = new QGridLayout();
+ textGrid.setContentsMargins(10, 10,-10, -10);
+ useDefault = new QCheckBox();
+ iconButton = new QPushButton();
+ iconButton.setSizePolicy(Policy.Fixed, Policy.Fixed);
+ iconButton.clicked.connect(this, "iconButtonPressed()");
+ useDefault.setText(tr("Use Default"));
+ iconButton.setIcon(i);
+
+ textGrid.addWidget(iconButton,1,1);
+ textGrid.addWidget(useDefault,2,1);
+ useDefault.clicked.connect(this, "useDefaultIconChecked(Boolean)");
+ grid.addLayout(textGrid,1,1);
+
+ QGridLayout buttonGrid = new QGridLayout();
+ ok = new QPushButton(tr("OK"));
+ ok.clicked.connect(this, "okButtonPressed()");
+ ok.setEnabled(false);
+ QPushButton cancel = new QPushButton(tr("Cancel"));
+ cancel.clicked.connect(this, "cancelButtonPressed()");
+ buttonGrid.addWidget(ok, 3, 1);
+ buttonGrid.addWidget(cancel, 3,2);
+ grid.addLayout(buttonGrid,2,1);
+ }
+
+ // The OK button was pressed
+ @SuppressWarnings("unused")
+ private void okButtonPressed() {
+ okPressed = true;
+ close();
+ }
+
+ // The CANCEL button was pressed
+ @SuppressWarnings("unused")
+ private void cancelButtonPressed() {
+ okPressed = false;
+ close();
+ }
+
+ // Check if the OK button was pressed
+ public boolean okPressed() {
+ return okPressed;
+ }
+
+ // Icon Button pressed
+ private void iconButtonPressed() {
+ QFileDialog fd = new QFileDialog(this);
+ fd.setFileMode(FileMode.ExistingFile);
+ fd.setConfirmOverwrite(true);
+ fd.setWindowTitle(tr("Icon"));
+ fd.setFilter(tr("PNG (*.png);;All Files (*.*)"));
+ fd.setAcceptMode(AcceptMode.AcceptOpen);
+ fd.setDirectory(System.getProperty("user.home"));
+ if (fd.exec() == 0 || fd.selectedFiles().size() == 0) {
+ return;
+ }
+
+ ok.setEnabled(true);
+ String path = fd.selectedFiles().get(0);
+ QIcon icon = new QIcon(path);
+ iconButton.setIcon(new QIcon(path));
+ iconButton.setSizePolicy(Policy.Fixed, Policy.Fixed);
+ }
+
+ public void setUseDefaultIcon(boolean val) {
+ useDefault.setChecked(val);
+ iconButton.setEnabled(!val);
+ startUseDefault = val;
+ }
+
+ public QIcon getIcon() {
+ if (useDefault.isChecked())
+ return null;
+ return iconButton.icon();
+ }
+
+ public void useDefaultIconChecked(Boolean value) {
+ iconButton.setEnabled(!value);
+
+ if (value != startUseDefault)
+ ok.setEnabled(true);
+ else
+ ok.setEnabled(false);
+ }
+
+ public String getFileType() {
+ return "PNG";
+ }
+}
public QAction notebookAddAction; // Add a new notebook\r
public QAction notebookDeleteAction; // Delete a notebook\r
public QAction notebookCloseAction; // Close notebooks\r
+ public QAction notebookIconAction; // Change the icon\r
\r
public QAction savedSearchAddAction; // Add a saved search\r
public QAction savedSearchEditAction; // Edit a saved search\r
setupShortcut(notebookDeleteAction, "File_Notebook_Delete");\r
\r
notebookCloseAction = new QAction(tr("Open/Close Notebooks"), this);\r
-// if (!Global.mimicEvernoteInterface) {\r
- notebookCloseAction.setEnabled(true);\r
- notebookCloseAction.triggered.connect(parent, "closeNotebooks()");\r
- setupShortcut(notebookCloseAction, "File_Notebook_Close");\r
-// } else {\r
-// notebookCloseAction.setEnabled(false); \r
-// }\r
+ notebookCloseAction.setEnabled(true);\r
+ notebookCloseAction.triggered.connect(parent, "closeNotebooks()");\r
+ setupShortcut(notebookCloseAction, "File_Notebook_Close");\r
+\r
+ notebookIconAction = new QAction(tr("Change Icon"), this);\r
+ notebookIconAction.setEnabled(false);\r
+ notebookIconAction.triggered.connect(parent, "setNotebookIcon()");\r
+ setupShortcut(notebookIconAction, "File_Notebook_Icon");\r
\r
tagAddAction = new QAction(tr("Add"),this);\r
tagAddAction.triggered.connect(parent, "addTag()");\r
notebookMenu.addAction(notebookAddAction);\r
notebookMenu.addAction(notebookEditAction);\r
notebookMenu.addAction(notebookDeleteAction);\r
-// if (!Global.mimicEvernoteInterface) {\r
- notebookMenu.addSeparator();\r
- notebookMenu.addAction(notebookCloseAction);\r
-// }\r
+ notebookMenu.addSeparator();\r
+ notebookMenu.addAction(notebookCloseAction);\r
+ notebookMenu.addSeparator();\r
+ notebookMenu.addAction(notebookIconAction);\r
\r
tagMenu.addAction(tagAddAction);\r
tagMenu.addAction(tagEditAction);\r
package cx.fbn.nevernote.gui;\r
\r
import java.util.ArrayList;\r
+import java.util.HashMap;\r
import java.util.List;\r
\r
import com.evernote.edam.type.Notebook;\r
private QAction deleteAction;\r
private QAction addAction;\r
private QAction editAction;\r
+ private QAction iconAction;\r
public NoteSignal noteSignal;\r
+ private HashMap<String, QIcon> icons;\r
// private final QTreeWidgetItem previousMouseOver;\r
// private boolean previousMouseOverWasSelected;\r
\r
editAction = e;\r
}\r
\r
+ public void setIconAction(QAction e) {\r
+ iconAction = e;\r
+ }\r
+ \r
public NotebookTreeWidget() {\r
noteSignal = new NoteSignal();\r
setProperty("hideTree", true);\r
return false;\r
}\r
\r
+ public void setIcons(HashMap<String, QIcon> i) {\r
+ icons = i;\r
+ }\r
\r
- public void load(List<Notebook> books, List<String> localBooks) {\r
- Notebook book;\r
- QTreeWidgetItem child;\r
- clear();\r
+ public QIcon findDefaultIcon(String guid, String name, List<String> localBooks, boolean isPublished) {\r
String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
QIcon blueIcon = new QIcon(iconPath+"notebook-blue.png");\r
QIcon greenIcon = new QIcon(iconPath+"notebook-green.png");\r
QIcon redIcon = new QIcon(iconPath+"notebook-red.png");\r
QIcon yellowIcon = new QIcon(iconPath+"notebook-yellow.png");\r
+\r
+ if (localBooks.contains(guid)) {\r
+ return yellowIcon;\r
+ }\r
+ \r
+ if (localBooks.contains(guid) && \r
+ (name.equalsIgnoreCase("Conflicting Changes") ||\r
+ name.equalsIgnoreCase("Conflicting Changes (Local)")))\r
+ return redIcon;\r
+ if (isPublished)\r
+ return blueIcon;\r
+\r
+ return greenIcon;\r
+ }\r
+ \r
+ public void load(List<Notebook> books, List<String> localBooks) {\r
+ Notebook book;\r
+ QTreeWidgetItem child;\r
+ clear();\r
\r
if (books == null)\r
return;\r
Qt.Alignment ra = new Qt.Alignment(Qt.AlignmentFlag.AlignRight);\r
for (int i=0; i<books.size(); i++) {\r
- book = books.get(i);\r
- child = new QTreeWidgetItem();\r
- child.setText(0, book.getName());\r
- child.setIcon(0, greenIcon);\r
- if (localBooks.contains(book.getGuid()))\r
- child.setIcon(0, yellowIcon);\r
- if (localBooks.contains(book.getGuid()) && \r
- (book.getName().equalsIgnoreCase("Conflicting Changes") ||\r
- book.getName().equalsIgnoreCase("Conflicting Changes (Local)")))\r
- child.setIcon(0, redIcon);\r
- if (book.isPublished())\r
- child.setIcon(0, blueIcon);\r
+ book = books.get(i);\r
+ child = new QTreeWidgetItem();\r
+ child.setText(0, book.getName());\r
+ if (icons != null && !icons.containsKey(book.getGuid())) {\r
+ QIcon icon = findDefaultIcon(book.getGuid(), book.getName(), localBooks, book.isPublished());\r
+ child.setIcon(0, icon);\r
+ } else {\r
+ child.setIcon(0, icons.get(book.getGuid()));\r
+ }\r
child.setTextAlignment(1, ra.value());\r
child.setText(2, book.getGuid());\r
addTopLevelItem(child);\r
\r
sortItems(0, SortOrder.AscendingOrder); \r
if (Global.mimicEvernoteInterface) {\r
+ String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
+ QIcon greenIcon = new QIcon(iconPath+"notebook-green.png");\r
+ \r
child = new QTreeWidgetItem();\r
child.setIcon(0, greenIcon);\r
child.setText(0, "All Notebooks");\r
menu.addAction(addAction);\r
menu.addAction(editAction);\r
menu.addAction(deleteAction);\r
+ menu.addSeparator();\r
+ menu.addAction(iconAction);\r
menu.exec(event.globalPos());\r
}\r
\r
import java.text.ParseException;\r
import java.text.SimpleDateFormat;\r
import java.util.ArrayList;\r
+import java.util.HashMap;\r
import java.util.List;\r
\r
import com.evernote.edam.type.Notebook;\r
+import com.trolltech.qt.core.QBuffer;\r
+import com.trolltech.qt.core.QByteArray;\r
+import com.trolltech.qt.core.QIODevice;\r
+import com.trolltech.qt.gui.QIcon;\r
+import com.trolltech.qt.gui.QImage;\r
+import com.trolltech.qt.gui.QPixmap;\r
\r
import cx.fbn.nevernote.sql.driver.NSqlQuery;\r
import cx.fbn.nevernote.utilities.ApplicationLogger;\r
logger.log(logger.EXTREME, "Error setting default notebook.");\r
}\r
\r
+ // Get a list of all icons\r
+ public HashMap<String, QIcon> getAllIcons() {\r
+ HashMap<String, QIcon> values = new HashMap<String, QIcon>();\r
+ NSqlQuery query = new NSqlQuery(db.getConnection());\r
\r
+ if (!query.exec("SELECT guid, icon from notebook where ARCHIVED != true"))\r
+ logger.log(logger.EXTREME, "Error executing notebook getAllIcons select.");\r
+ while (query.next()) {\r
+ if (query.getBlob(1) != null) {\r
+ String guid = query.valueString(0);\r
+ QByteArray blob = new QByteArray(query.getBlob(1));\r
+ QIcon icon = new QIcon(QPixmap.fromImage(QImage.fromData(blob)));\r
+ values.put(guid, icon);\r
+ }\r
+ }\r
+ return values;\r
+ }\r
+ \r
+ // Get the notebooks custom icon\r
+ public QIcon getIcon(String guid) {\r
+ NSqlQuery query = new NSqlQuery(db.getConnection());\r
+ \r
+ if (!query.prepare("Select icon from notebook where guid=:guid"))\r
+ logger.log(logger.EXTREME, "Error preparing notebook icon select.");\r
+ query.bindValue(":guid", guid);\r
+ if (!query.exec())\r
+ logger.log(logger.EXTREME, "Error finding notebook icon.");\r
+ if (!query.next() || query.getBlob(0) == null)\r
+ return null;\r
+ \r
+ QByteArray blob = new QByteArray(query.getBlob(0));\r
+ QIcon icon = new QIcon(QPixmap.fromImage(QImage.fromData(blob)));\r
+ return icon;\r
+ }\r
+ // Set the notebooks custom icon\r
+ public void setIcon(String guid, QIcon icon, String type) {\r
+ NSqlQuery query = new NSqlQuery(db.getConnection());\r
+ if (icon == null) {\r
+ if (!query.prepare("update notebook set icon=null where guid=:guid"))\r
+ logger.log(logger.EXTREME, "Error preparing notebook icon select.");\r
+ } else {\r
+ if (!query.prepare("update notebook set icon=:icon where guid=:guid"))\r
+ logger.log(logger.EXTREME, "Error preparing notebook icon select.");\r
+ QBuffer buffer = new QBuffer();\r
+ if (!buffer.open(QIODevice.OpenModeFlag.ReadWrite)) {\r
+ logger.log(logger.EXTREME, "Failure to open buffer. Aborting.");\r
+ return;\r
+ }\r
+ QPixmap p = icon.pixmap(32, 32);\r
+ QImage i = p.toImage();\r
+ i.save(buffer, type.toUpperCase());\r
+ buffer.close();\r
+ QByteArray b = new QByteArray(buffer.buffer());\r
+ if (!b.isNull() && !b.isEmpty())\r
+ query.bindValue(":icon", b.toByteArray());\r
+ else\r
+ return;\r
+ }\r
+ query.bindValue(":guid", guid);\r
+ if (!query.exec()) \r
+ logger.log(logger.LOW, "Error setting notebook icon. " +query.lastError());\r
+ }\r
\r
// does a record exist?\r
public String findNotebookByName(String newname) {\r