Neal Wilson 10 years ago
parent
commit
13f1ec4cd6
2 changed files with 34 additions and 0 deletions
  1. 10
    0
      config/Windows/batchdetailsnew.xml
  2. 24
    0
      src/typica.w

+ 10
- 0
config/Windows/batchdetailsnew.xml View File

8
         </layout>
8
         </layout>
9
         <webview id="view" />
9
         <webview id="view" />
10
     </layout>
10
     </layout>
11
+	<menu name="File">
12
+		<item id="save" shortcut="Ctrl+S">Save…</item>
13
+	</menu>
11
     <program>
14
     <program>
12
         <![CDATA[
15
         <![CDATA[
13
 			var window = this;
16
 			var window = this;
334
 				query = query.invalidate();
337
 				query = query.invalidate();
335
 				edit.enabled = true;
338
 				edit.enabled = true;
336
 			};
339
 			};
340
+			var saveMenu = findChildObject(this, 'save');
341
+			saveMenu.triggered.connect(function() {
342
+				var filename = QFileDialog.getSaveFileName(window, "Save Log As…", QSettings.value("script/lastDir", "") + "/");
343
+				if(filename != "") {
344
+					saveFileFromDatabase(fileID, filename);
345
+				}
346
+			});
337
         ]]>
347
         ]]>
338
     </program>
348
     </program>
339
 </window>
349
 </window>

+ 24
- 0
src/typica.w View File

3663
 QScriptValue annotationFromRecord(QScriptContext *context,
3663
 QScriptValue annotationFromRecord(QScriptContext *context,
3664
                                   QScriptEngine *engine);
3664
                                   QScriptEngine *engine);
3665
 QScriptValue setTabOrder(QScriptContext *context, QScriptEngine *engine);
3665
 QScriptValue setTabOrder(QScriptContext *context, QScriptEngine *engine);
3666
+QScriptValue saveFileFromDatabase(QScriptContext *context, QScriptEngine *engine);
3666
 
3667
 
3667
 @ These functions are passed to the scripting engine.
3668
 @ These functions are passed to the scripting engine.
3668
 
3669
 
3676
                                    engine->newFunction(annotationFromRecord));
3677
                                    engine->newFunction(annotationFromRecord));
3677
 engine->globalObject().setProperty("setTabOrder",
3678
 engine->globalObject().setProperty("setTabOrder",
3678
                                    engine->newFunction(setTabOrder));
3679
                                    engine->newFunction(setTabOrder));
3680
+engine->globalObject().setProperty("saveFileFromDatabase",
3681
+                                   engine->newFunction(saveFileFromDatabase));
3679
 
3682
 
3680
 @ These functions are not part of an object. They expect a string specifying
3683
 @ These functions are not part of an object. They expect a string specifying
3681
 the path to a file and return a string with either the name of the file without
3684
 the path to a file and return a string with either the name of the file without
3697
 	return retval;
3700
 	return retval;
3698
 }
3701
 }
3699
 
3702
 
3703
+@ This function takes a file ID and a file name and copies file data stored in
3704
+the database out to the file system.
3705
+
3706
+@<Functions for scripting@>=
3707
+QScriptValue saveFileFromDatabase(QScriptContext *context, QScriptEngine *engine)
3708
+{
3709
+	SqlQueryConnection h;
3710
+	QSqlQuery *query = h.operator->();
3711
+	QString q = "SELECT file FROM files WHERE id = :file";
3712
+	query->prepare(q);
3713
+	query->bindValue(":file", argument<int>(0, context));
3714
+	query->exec();
3715
+	query->next();
3716
+	QByteArray array = query->value(0).toByteArray();
3717
+	QFile file(argument<QString>(1, context));
3718
+	file.open(QIODevice::WriteOnly);
3719
+	file.write(array);
3720
+	file.close();
3721
+	return QScriptValue();
3722
+}
3723
+
3700
 @ This function takes a string representing a SQL array and returns an array
3724
 @ This function takes a string representing a SQL array and returns an array
3701
 value.
3725
 value.
3702
 
3726
 

Loading…
Cancel
Save