OSDN Git Service

Cleanup compiler warning messages and alter backup & restore to handle new database...
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / SetIcon.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 com.trolltech.qt.gui.QCheckBox;
23 import com.trolltech.qt.gui.QDialog;
24 import com.trolltech.qt.gui.QFileDialog;
25 import com.trolltech.qt.gui.QFileDialog.AcceptMode;
26 import com.trolltech.qt.gui.QFileDialog.FileMode;
27 import com.trolltech.qt.gui.QGridLayout;
28 import com.trolltech.qt.gui.QIcon;
29 import com.trolltech.qt.gui.QPushButton;
30 import com.trolltech.qt.gui.QSizePolicy.Policy;
31
32 public class SetIcon extends QDialog {
33         private boolean okPressed;
34         QPushButton     ok;
35         QPushButton             iconButton;
36         QCheckBox               useDefault;
37         QIcon                   defaultIcon;
38         boolean                 startUseDefault;
39         private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
40         
41         // Constructor
42         public SetIcon(QIcon i) {
43                 okPressed = false;
44                 setWindowTitle(tr("Set Icon"));
45                 QGridLayout grid = new QGridLayout();
46                 setWindowIcon(new QIcon(iconPath+"nevernote.png"));
47                 setLayout(grid);
48                 
49                 QGridLayout textGrid = new QGridLayout();
50                 textGrid.setContentsMargins(10, 10,-10, -10);
51                 useDefault = new QCheckBox();
52                 iconButton = new QPushButton();
53                 iconButton.setSizePolicy(Policy.Fixed, Policy.Fixed);
54                 iconButton.clicked.connect(this, "iconButtonPressed()");
55                 useDefault.setText(tr("Use Default"));
56                 iconButton.setIcon(i);
57                 
58                 textGrid.addWidget(iconButton,1,1);
59                 textGrid.addWidget(useDefault,2,1);
60                 useDefault.clicked.connect(this, "useDefaultIconChecked(Boolean)");
61                 grid.addLayout(textGrid,1,1);
62                 
63                 QGridLayout buttonGrid = new QGridLayout();
64                 ok = new QPushButton(tr("OK"));
65                 ok.clicked.connect(this, "okButtonPressed()");
66                 ok.setEnabled(false);
67                 QPushButton cancel = new QPushButton(tr("Cancel"));
68                 cancel.clicked.connect(this, "cancelButtonPressed()");
69                 buttonGrid.addWidget(ok, 3, 1);
70                 buttonGrid.addWidget(cancel, 3,2);
71                 grid.addLayout(buttonGrid,2,1);
72         }
73         
74         // The OK button was pressed
75         @SuppressWarnings("unused")
76         private void okButtonPressed() {
77                 okPressed = true;
78                 close();
79         }
80         
81         // The CANCEL button was pressed
82         @SuppressWarnings("unused")
83         private void cancelButtonPressed() {
84                 okPressed = false;
85                 close();
86         }
87         
88         // Check if the OK button was pressed
89         public boolean okPressed() {
90                 return okPressed;
91         }
92         
93         // Icon Button pressed
94         @SuppressWarnings("unused")
95         private void iconButtonPressed() {
96                 QFileDialog fd = new QFileDialog(this);
97                 fd.setFileMode(FileMode.ExistingFile);
98                 fd.setConfirmOverwrite(true);
99                 fd.setWindowTitle(tr("Icon"));
100                 fd.setFilter(tr("PNG (*.png);;All Files (*.*)"));
101                 fd.setAcceptMode(AcceptMode.AcceptOpen);
102                 fd.setDirectory(System.getProperty("user.home"));
103                 if (fd.exec() == 0 || fd.selectedFiles().size() == 0) {
104                         return;
105                 }
106                 
107                 ok.setEnabled(true);
108                 String path = fd.selectedFiles().get(0);
109                 iconButton.setIcon(new QIcon(path));
110                 iconButton.setSizePolicy(Policy.Fixed, Policy.Fixed);
111         }
112         
113         public void setUseDefaultIcon(boolean val) {
114                 useDefault.setChecked(val);
115                 iconButton.setEnabled(!val);
116                 startUseDefault = val;
117         }
118         
119         public QIcon getIcon() {
120                 if (useDefault.isChecked())
121                         return null;
122                 return iconButton.icon();
123         }
124         
125         public void useDefaultIconChecked(Boolean value) {
126                 iconButton.setEnabled(!value);
127                 
128                 if (value != startUseDefault) 
129                         ok.setEnabled(true);
130                 else
131                         ok.setEnabled(false);
132         }
133         
134         public String getFileType() {
135                 return "PNG";
136         }
137 }