OSDN Git Service

Added the ability to select the encryption method.
authorRandy Baumgarte <randy@fbn.cx>
Wed, 29 Sep 2010 16:12:46 +0000 (12:12 -0400)
committerRandy Baumgarte <randy@fbn.cx>
Fri, 1 Oct 2010 16:44:05 +0000 (12:44 -0400)
src/cx/fbn/nevernote/NeverNote.java
src/cx/fbn/nevernote/dialog/DBEncryptDialog.java

index 983f644..dfc165c 100644 (file)
@@ -686,13 +686,14 @@ public class NeverNote extends QMainWindow{
         try {
                Statement st = conn.getConnection().createStatement();  
                st.execute("shutdown");
-               QMessageBox box = new QMessageBox();
-                       box.setText("Encrypting Database");
-                       box.show();
-                       ChangeFileEncryption.execute(dbPath, dbName, encryptCipher, null, Global.cipherPassword.toCharArray(), true);
-                       Global.setDatabaseUrl(Global.getDatabaseUrl() + ";CIPHER="+encryptCipher);
-                       box.setText("Encryption Complete");
-                       box.close();
+               if (QMessageBox.question(this, "Are you sure", 
+                               "Are you sure you wish to encrypt the database?",
+                               QMessageBox.StandardButton.Yes, 
+                               QMessageBox.StandardButton.No) == StandardButton.Yes.value()) {
+                       ChangeFileEncryption.execute(dbPath, dbName, encryptCipher, null, Global.cipherPassword.toCharArray(), true);
+                       Global.setDatabaseUrl(Global.getDatabaseUrl() + ";CIPHER="+encryptCipher);
+                       QMessageBox.information(this, "Encryption Complete", "Encryption is complete");
+               }
         } catch (SQLException e) {
                        e.printStackTrace();
                }       
@@ -709,13 +710,15 @@ public class NeverNote extends QMainWindow{
                        encryptCipher = "AES";
                else
                        encryptCipher = "XTEA";
-               QMessageBox box = new QMessageBox();
-                       box.setText("Decrypting Database");
-                       box.show();
-                       ChangeFileEncryption.execute(dbPath, dbName, encryptCipher, Global.cipherPassword.toCharArray(), null, true);
-                       Global.setDatabaseUrl("");
-                       box.setText("Decryption Complete");
-                       box.close();
+               if (QMessageBox.question(this, tr("Confirmation"), tr("Are you sure", 
+                               "Are you sure you wish to decrypt the database?"),
+                               QMessageBox.StandardButton.Yes, 
+                               QMessageBox.StandardButton.No) == StandardButton.Yes.value()) {
+
+                       ChangeFileEncryption.execute(dbPath, dbName, encryptCipher, Global.cipherPassword.toCharArray(), null, true);
+                       Global.setDatabaseUrl("");
+                       QMessageBox.information(this, tr("Decryption Complete"), tr("Decryption is complete"));
+               }
                } catch (SQLException e) {
                        e.printStackTrace();
                }       
@@ -740,15 +743,16 @@ public class NeverNote extends QMainWindow{
                if (dialog.okPressed()) {
                        Global.cipherPassword = dialog.getPassword();
                        encryptOnShutdown  = true;
-                       encryptCipher = "AES";
+                       encryptCipher = dialog.getEncryptionMethod();
                }
         } else {
             DBEncryptDialog dialog = new DBEncryptDialog();
             dialog.setWindowTitle("Database Decryption");
+            dialog.hideEncryption();
             dialog.exec();
             if (dialog.okPressed()) {
                if (!dialog.getPassword().equals(Global.cipherPassword)) {
-                       QMessageBox.critical(null, "Incorrect Password", "Incorrect Password");
+                       QMessageBox.critical(null, tr("Incorrect Password"), tr("Incorrect Password"));
                        return;
                }
                decryptOnShutdown  = true;
index 252d41c..f20c24f 100644 (file)
@@ -19,6 +19,7 @@
 \r
 package cx.fbn.nevernote.dialog;\r
 \r
+import com.trolltech.qt.gui.QComboBox;\r
 import com.trolltech.qt.gui.QDialog;\r
 import com.trolltech.qt.gui.QGridLayout;\r
 import com.trolltech.qt.gui.QLabel;\r
@@ -31,6 +32,8 @@ public class DBEncryptDialog extends QDialog {
        private final QLineEdit password1;\r
        private final QLineEdit password2;\r
        private final QPushButton ok;\r
+       private final QComboBox encryptionType;\r
+       private final QLabel encryptionLabel;\r
        \r
        \r
        // Constructor\r
@@ -50,13 +53,22 @@ public class DBEncryptDialog extends QDialog {
                password1.textChanged.connect(this, "validateInput()");\r
                password2.textChanged.connect(this, "validateInput()");\r
                \r
+               encryptionLabel = new QLabel("Encryption Method");\r
+               encryptionType = new QComboBox();\r
+               encryptionType.addItem(tr("AES"), "AES");\r
+               encryptionType.addItem(tr("XTEA"), "XTEA");\r
+               \r
                passwordGrid.addWidget(new QLabel(tr("Password")), 1,1);\r
                passwordGrid.addWidget(password1, 1, 2);\r
                passwordGrid.addWidget(new QLabel(tr("Verify Password")), 2,1);\r
                passwordGrid.addWidget(password2, 2, 2);\r
+               passwordGrid.addWidget(encryptionLabel, 3,1);\r
+               passwordGrid.addWidget(encryptionType, 3,2);\r
                passwordGrid.setContentsMargins(10, 10,  -10, -10);\r
                grid.addLayout(passwordGrid,1,1);\r
                \r
+               \r
+               \r
                ok = new QPushButton(tr("OK"));\r
                ok.setEnabled(false);\r
                ok.clicked.connect(this, "okButtonPressed()");\r
@@ -67,6 +79,16 @@ public class DBEncryptDialog extends QDialog {
                grid.addLayout(buttonGrid,2,1);\r
        }\r
        \r
+       public void hideEncryption() {\r
+               encryptionType.setVisible(false);\r
+               encryptionLabel.setVisible(false);\r
+       }\r
+       \r
+       public String getEncryptionMethod() {\r
+               int i = encryptionType.currentIndex();\r
+               return encryptionType.itemData(i).toString();\r
+       }\r
+       \r
        // The OK button was pressed\r
        @SuppressWarnings("unused")\r
        private void okButtonPressed() {\r