OSDN Git Service

Added the ability to view debugging logs.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / LogFileDialog.java
1 /*\r
2  * This file is part of NeverNote \r
3  * Copyright 2009 Randy Baumgarte\r
4  * \r
5  * This file may be licensed under the terms of of the\r
6  * GNU General Public License Version 2 (the ``GPL'').\r
7  *\r
8  * Software distributed under the License is distributed\r
9  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either\r
10  * express or implied. See the GPL for the specific language\r
11  * governing rights and limitations.\r
12  *\r
13  * You should have received a copy of the GPL along with this\r
14  * program. If not, go to http://www.gnu.org/licenses/gpl.html\r
15  * or write to the Free Software Foundation, Inc.,\r
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
17  *\r
18 */\r
19 \r
20 package cx.fbn.nevernote.dialog;\r
21 \r
22 import java.io.BufferedReader;\r
23 import java.io.File;\r
24 import java.io.FileNotFoundException;\r
25 import java.io.FileReader;\r
26 import java.io.IOException;\r
27 import java.util.List;\r
28 \r
29 import com.trolltech.qt.gui.QComboBox;\r
30 import com.trolltech.qt.gui.QDialog;\r
31 import com.trolltech.qt.gui.QHBoxLayout;\r
32 import com.trolltech.qt.gui.QIcon;\r
33 import com.trolltech.qt.gui.QLabel;\r
34 import com.trolltech.qt.gui.QTextEdit;\r
35 import com.trolltech.qt.gui.QVBoxLayout;\r
36 \r
37 import cx.fbn.nevernote.Global;\r
38 \r
39 public class LogFileDialog extends QDialog {\r
40         public final QComboBox          fileCombo;       \r
41         public final QTextEdit          textField;\r
42         private final List<String>              logs;\r
43         private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
44         \r
45         // Constructor\r
46         public LogFileDialog(List<String> l) {\r
47                 setWindowTitle(tr("Application Logs"));\r
48                 logs = l;\r
49                 setWindowIcon(new QIcon(iconPath+"notebook-green.png"));\r
50                 QVBoxLayout main = new QVBoxLayout();\r
51                 setLayout(main);\r
52                 fileCombo = new QComboBox(this);\r
53                 \r
54                 QHBoxLayout comboLayout = new QHBoxLayout();\r
55                 comboLayout.addWidget(new QLabel(tr("Log File:")));\r
56                 comboLayout.addWidget(fileCombo);\r
57                 comboLayout.addStretch(100);\r
58                 fileCombo.currentIndexChanged.connect(this, "indexChanged(Integer)");\r
59                 \r
60                 main.addLayout(comboLayout);\r
61                                 \r
62                 textField = new QTextEdit(this);\r
63                 main.addWidget(textField);\r
64                 \r
65                 fileCombo.addItem(tr("Message Log"), "MessageLog");\r
66                 fileCombo.addItem(tr("Application Log"), "NeverNoteLog");\r
67                 fileCombo.addItem(tr("Synchronization Log"), "SyncLog");\r
68                 fileCombo.addItem(tr("Save Log"), "SaveLog");\r
69                 fileCombo.addItem(tr("Tag Counter Log"), "TagCounterLog");\r
70                 fileCombo.addItem(tr("Notebook Counter Log"), "NotebookCounterLog");\r
71                 fileCombo.addItem(tr("Trash Counter Log"), "TrashCounterLog");\r
72                 fileCombo.addItem(tr("Note Browser Log"), "NoteBrowserLog");\r
73                 fileCombo.addItem(tr("Export Log"), "ExportLog");\r
74                 fileCombo.addItem(tr("Import Log"), "ImportLog");\r
75 //              fileCombo.addItem(tr("Global Log"), "GlobalLog");\r
76                 fileCombo.addItem(tr("Index Log"), "IndexLog");\r
77                 fileCombo.addItem(tr("Database Connection Log"), "DatabaseLog");\r
78                 fileCombo.addItem(tr("Thumbnail Generator Log"), "ThumbnailLog");\r
79                 fileCombo.addItem(tr("NeverNote Database SQL Trace File"), "NeverNoteDBLog");\r
80                 fileCombo.addItem(tr("Index Database SQL Trace File"), "IndexDBLog");\r
81                 fileCombo.addItem(tr("Resource Database SQL Trace File"), "ResourceDBLog");\r
82                 \r
83                 \r
84         }\r
85         \r
86         @SuppressWarnings("unused")\r
87         private void restoreAsNewPushed() {\r
88                 this.close();\r
89         }\r
90         @SuppressWarnings("unused")\r
91         private void restorePushed() {\r
92                 this.close();\r
93         }\r
94         @SuppressWarnings("unused")\r
95         private void cancelPressed() {\r
96                 this.close();\r
97         }\r
98         \r
99         @SuppressWarnings("unused")\r
100         private void indexChanged(Integer index) {\r
101                 String value = (String) fileCombo.itemData(index);\r
102 \r
103                 if (value.equals("MessageLog")) {\r
104                         textField.clear();\r
105                         for (int i=0; i<logs.size(); i++) {\r
106                                 textField.append(logs.get(i));\r
107                         }\r
108                         return;\r
109                 }               \r
110                 if (value.equals("NeverNoteLog")) {\r
111                         loadFile("nevernote.log");\r
112                         return;\r
113                 }\r
114                 if (value.equals("SyncLog")) {\r
115                         loadFile("syncRunner.log");\r
116                         return;\r
117                 }\r
118                 if (value.equals("SaveLog")) {\r
119                         loadFile("saveRunner.log");\r
120                         return;\r
121                 }\r
122                 if (value.equals("SaveLog")) {\r
123                         loadFile("saveRunner.log");\r
124                         return;\r
125                 }\r
126                 if (value.equals("TagCounterLog")) {\r
127                         loadFile("tag_counter.log");\r
128                         return;\r
129                 }\r
130                 if (value.equals("NotebookCounterLog")) {\r
131                         loadFile("notebook_counter.log");\r
132                         return;\r
133                 }\r
134                 if (value.equals("TrashCounterLog")) {\r
135                         loadFile("trash_counter.log");\r
136                         return;\r
137                 }\r
138                 if (value.equals("NoteBrowserLog")) {\r
139                         loadFile("browser.log");\r
140                         return;\r
141                 }\r
142                 if (value.equals("ExportLog")) {\r
143                         loadFile("export.log");\r
144                         return;\r
145                 }\r
146                 if (value.equals("ImportLog")) {\r
147                         loadFile("import.log");\r
148                         return;\r
149                 }\r
150                 if (value.equals("GlobalLog")) {\r
151                         loadFile("global.log");\r
152                         return;\r
153                 }\r
154                 if (value.equals("IndexLog")) {\r
155                         loadFile("indexRunner.log");\r
156                         return;\r
157                 }\r
158                 if (value.equals("DatabaseLog")) {\r
159                         loadFile("nevernote-database.log");\r
160                         return;\r
161                 }\r
162                 if (value.equals("ThumbnailLog")) {\r
163                         loadFile("thumbnailRunner.log");\r
164                         return;\r
165                 }\r
166                 if (value.equals("NeverNoteDBLog")) {\r
167                         loadTraceFile("NeverNote.trace.db");\r
168                         return;\r
169                 }       \r
170                 if (value.equals("IndexDBLog")) {\r
171                         loadTraceFile("Index.trace.db");\r
172                         return;\r
173                 }       \r
174                 if (value.equals("ResourceDBLog")) {\r
175                         loadTraceFile("Resources.trace.db");\r
176                         return;\r
177                 }       \r
178         }\r
179         \r
180         private void loadFile(String file) {\r
181                 textField.clear();\r
182                 File f = Global.getFileManager().getLogsDirFile(file);\r
183                 try {\r
184                         BufferedReader in = new BufferedReader(new FileReader(f.getAbsolutePath()));\r
185                         String data;\r
186                         while ((data=in.readLine()) != null) {\r
187                                 textField.append(data);\r
188                         }\r
189                 } catch (FileNotFoundException e) {\r
190                         e.printStackTrace();\r
191                         return;\r
192                 } catch (IOException e) {\r
193                         // TODO Auto-generated catch block\r
194                         e.printStackTrace();\r
195                 }               \r
196         }\r
197                 \r
198         private void loadTraceFile(String file) {\r
199                 textField.clear();\r
200                 File f = Global.getFileManager().getDbDirFile(file);\r
201                 try {\r
202                         BufferedReader in = new BufferedReader(new FileReader(f.getAbsolutePath()));\r
203                         String data;\r
204                         while ((data=in.readLine()) != null) {\r
205                                 textField.append(data);\r
206                         }\r
207                 } catch (FileNotFoundException e) {\r
208                         return;\r
209                 } catch (IOException e) {\r
210                         e.printStackTrace();\r
211                 }\r
212         }\r
213 }\r
214  \r
215 \r
216 \r
217         \r
218         \r
219         \r
220         \r
221 \r