Commit a1f2bba2 authored by Claes Sjofors's avatar Claes Sjofors Committed by Claes Sjöfors

Xtt eventlist and eventlog, File/Export added

parent b0ef4d54
......@@ -1287,7 +1287,7 @@ void WttGtk::activate_openfile_dbs(GtkWidget* w, gpointer data)
wtt->set_clock_cursor();
wtt->wnav->wow->CreateFileSelDia("Loadfile Selection", (void*)wtt,
Wtt::file_selected_cb, wow_eFileSelType_Dbs);
Wtt::file_selected_cb, wow_eFileSelType_Dbs, wow_eFileSelAction_Open);
wtt->reset_cursor();
}
......@@ -1297,7 +1297,7 @@ void WttGtk::activate_openfile_wbl(GtkWidget* w, gpointer data)
wtt->set_clock_cursor();
wtt->wnav->wow->CreateFileSelDia("Loadfile Selection", (void*)wtt,
Wtt::file_selected_cb, wow_eFileSelType_Wbl);
Wtt::file_selected_cb, wow_eFileSelType_Wbl, wow_eFileSelAction_Open);
wtt->reset_cursor();
}
......
......@@ -1179,7 +1179,8 @@ void WttQtWidget::activate_openfile_dbs()
{
wtt->set_clock_cursor();
wtt->wnav->wow->CreateFileSelDia(
"Loadfile Selection", wtt, Wtt::file_selected_cb, wow_eFileSelType_Dbs);
"Loadfile Selection", wtt, Wtt::file_selected_cb, wow_eFileSelType_Dbs,
wow_eFileSelAction_Open);
wtt->reset_cursor();
}
......@@ -1187,7 +1188,8 @@ void WttQtWidget::activate_openfile_wbl()
{
wtt->set_clock_cursor();
wtt->wnav->wow->CreateFileSelDia(
"Loadfile Selection", wtt, Wtt::file_selected_cb, wow_eFileSelType_Wbl);
"Loadfile Selection", wtt, Wtt::file_selected_cb, wow_eFileSelType_Wbl,
wow_eFileSelAction_Open);
wtt->reset_cursor();
}
......
......@@ -100,7 +100,7 @@ void WbBckW::filter_cb(void* ctx, void* data, char* text)
void WbBckW::activate_open()
{
wow->CreateFileSelDia("Backup File Selection", (void*)this, file_selected_cb,
wow_eFileSelType_Backup);
wow_eFileSelType_Backup, wow_eFileSelAction_Open);
}
void WbBckW::file_selected_cb(
......@@ -138,7 +138,7 @@ void WbBckW::activate_diff()
return;
wow->CreateFileSelDia("Backup File Selection", (void*)this,
diff_file_selected_cb, wow_eFileSelType_Backup);
diff_file_selected_cb, wow_eFileSelType_Backup, wow_eFileSelAction_Open);
}
void WbBckW::diff_file_selected_cb(
......
......@@ -864,13 +864,19 @@ int CoWowGtk::GetSelection(GtkWidget* w, char* str, int size, GdkAtom atom)
void CoWowGtk::CreateFileSelDia(const char* title, void* parent_ctx,
void (*file_selected_cb)(void*, char*, wow_eFileSelType),
wow_eFileSelType file_type)
wow_eFileSelType file_type, wow_eFileSelAction action)
{
GtkWidget* dialog;
pwr_tFileName fname;
GtkFileChooserAction gaction;
if (action == wow_eFileSelAction_Open)
gaction = GTK_FILE_CHOOSER_ACTION_OPEN;
else
gaction = GTK_FILE_CHOOSER_ACTION_SAVE;
dialog = gtk_file_chooser_dialog_new(title, NULL,
GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
gaction, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
if (file_type == wow_eFileSelType_Dbs) {
......@@ -962,6 +968,10 @@ void CoWowGtk::CreateFileSelDia(const char* title, void* parent_ctx,
gtk_file_filter_set_name(filter, "All Files");
gtk_file_filter_add_pattern(filter, "*");
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
} else if (file_type == wow_eFileSelType_Tmp) {
pwr_tFileName folder;
dcli_translate_filename(folder, "$pwrp_tmp");
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), folder);
}
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
......
......@@ -144,7 +144,7 @@ public:
void DeleteList(void* ctx);
void CreateFileSelDia(const char* title, void* parent_ctx,
void (*file_selected_cb)(void*, char*, wow_eFileSelType),
wow_eFileSelType file_type);
wow_eFileSelType file_type, wow_eFileSelAction action);
int CreateModalDialog(const char* title, const char* text,
const char* button1, const char* button2, const char* button3,
const char* image);
......
......@@ -478,7 +478,7 @@ int CoWowQt::GetSelection(char* str, int size, const char* atom)
void CoWowQt::CreateFileSelDia(const char* title, void* parent_ctx,
void (*file_selected_cb)(void*, char*, wow_eFileSelType),
wow_eFileSelType file_type)
wow_eFileSelType file_type, wow_eFileSelAction action)
{
pwr_tFileName folder;
QString filter;
......@@ -500,11 +500,16 @@ void CoWowQt::CreateFileSelDia(const char* title, void* parent_ctx,
} else if (file_type == wow_eFileSelType_Backup) {
dcli_translate_filename(folder, "$pwrp_load");
filter = "Backup files (*.bck);;All Files (*)";
} else if (file_type == wow_eFileSelType_Tmp) {
dcli_translate_filename(folder, "$pwrp_tmp");
}
// QFileDialog::getOpenFileName() is broken
QFileDialog dialog(object->parent_wid, fl(title), fl(folder), filter);
if (action == wow_eFileSelAction_Open)
dialog.setFileMode(QFileDialog::ExistingFile);
else
dialog.setFileMode(QFileDialog::AnyFile);
int sts = dialog.exec();
if (sts == QDialog::Accepted && dialog.selectedFiles().length() > 0) {
......
......@@ -176,7 +176,7 @@ void CoWow::DeleteList(void* ctx)
void CoWow::CreateFileSelDia(const char* title, void* parent_ctx,
void (*file_selected_cb)(void*, char*, wow_eFileSelType),
wow_eFileSelType file_type)
wow_eFileSelType file_type, wow_eFileSelAction action)
{
}
......
......@@ -42,6 +42,11 @@
#include "co_wow_msg.h"
#include "co_lng.h"
typedef enum {
wow_eFileSelAction_Save,
wow_eFileSelAction_Open
} wow_eFileSelAction;
typedef enum {
wow_eFileSelType_,
wow_eFileSelType_All,
......@@ -53,6 +58,7 @@ typedef enum {
wow_eFileSelType_History,
wow_eFileSelType_Backup,
wow_eFileSelType_ColorTheme,
wow_eFileSelType_Tmp,
wow_eFileSelType__
} wow_eFileSelType;
......@@ -133,7 +139,7 @@ public:
virtual void DeleteList(void* ctx);
virtual void CreateFileSelDia(const char* title, void* parent_ctx,
void (*file_selected_cb)(void*, char*, wow_eFileSelType),
wow_eFileSelType file_type);
wow_eFileSelType file_type, wow_eFileSelAction action);
virtual int CreateModalDialog(const char* title, const char* text,
const char* button1, const char* button2, const char* button3,
const char* image);
......
......@@ -534,7 +534,7 @@ void GeCurveGtk::activate_export_browse(GtkWidget* w, gpointer data)
GeCurve* curve = (GeCurve*)data;
curve->wow->CreateFileSelDia(CoWowGtk::translate_utf8("File Selection"),
(void*)curve, export_file_selected_cb, wow_eFileSelType_History);
(void*)curve, export_file_selected_cb, wow_eFileSelType_History, wow_eFileSelAction_Open);
}
void GeCurveGtk::export_file_selected_cb(
......
......@@ -857,14 +857,14 @@ void GeGtk::activate_import_graph(GtkWidget* w, gpointer gectx)
{
((Ge*)gectx)
->wow->CreateFileSelDia("Graph Selection", (void*)gectx,
graph_file_selected_cb, wow_eFileSelType_Graph);
graph_file_selected_cb, wow_eFileSelType_Graph, wow_eFileSelAction_Open);
}
void GeGtk::activate_import_image(GtkWidget* w, gpointer gectx)
{
((Ge*)gectx)
->wow->CreateFileSelDia("Image Selection", (void*)gectx,
image_file_selected_cb, wow_eFileSelType_Image);
image_file_selected_cb, wow_eFileSelType_Image, wow_eFileSelAction_Open);
}
void GeGtk::activate_creanextpage(GtkWidget* w, gpointer gectx)
......
......@@ -821,14 +821,14 @@ void GeQtWidget::activate_customcolors_write()
void GeQtWidget::activate_import_graph()
{
ge->wow->CreateFileSelDia("Graph Selection", (void*)this,
GeQt::graph_file_selected_cb, wow_eFileSelType_Graph);
ge->wow->CreateFileSelDia("Graph Selection", ge,
GeQt::graph_file_selected_cb, wow_eFileSelType_Graph, wow_eFileSelAction_Open);
}
void GeQtWidget::activate_import_image()
{
ge->wow->CreateFileSelDia("Image Selection", (void*)this,
GeQt::image_file_selected_cb, wow_eFileSelType_Image);
ge->wow->CreateFileSelDia("Image Selection", ge,
GeQt::image_file_selected_cb, wow_eFileSelType_Image, wow_eFileSelAction_Open);
}
void GeQtWidget::activate_creanextpage()
......
......@@ -1626,7 +1626,7 @@ void Ge::activate_colortheme_next()
void Ge::activate_customcolors_read()
{
wow->CreateFileSelDia("CustomColors Selection", (void*)this,
customcolors_selected_cb, wow_eFileSelType_ColorTheme);
customcolors_selected_cb, wow_eFileSelType_ColorTheme, wow_eFileSelAction_Open);
}
void Ge::customcolors_selected_cb(
......
......@@ -156,6 +156,11 @@ EvGtk::EvGtk(void* ev_parent_ctx, GtkWidget* ev_parent_wid, char* eve_name,
g_signal_connect(
file_print, "activate", G_CALLBACK(eve_activate_print), this);
GtkWidget* file_export = gtk_image_menu_item_new_with_mnemonic(
CoWowGtk::translate_utf8("_Export"));
g_signal_connect(
file_export, "activate", G_CALLBACK(eve_activate_export), this);
GtkWidget* file_close = gtk_image_menu_item_new_with_mnemonic(
CoWowGtk::translate_utf8("_Close"));
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(file_close),
......@@ -167,6 +172,7 @@ EvGtk::EvGtk(void* ev_parent_ctx, GtkWidget* ev_parent_wid, char* eve_name,
GtkMenu* file_menu = (GtkMenu*)g_object_new(GTK_TYPE_MENU, NULL);
gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_print);
gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_export);
gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_close);
GtkWidget* file
......@@ -1214,7 +1220,12 @@ void EvGtk::blk_activate_print(GtkWidget* w, gpointer data)
ev->blk_activate_print();
}
void EvGtk::eve_activate_ack_last(GtkWidget* w, gpointer data)
void EvGtk::eve_activate_export(GtkWidget* w, gpointer ev)
{
((Ev*)ev)->eve_activate_export();
}
void EvGtk::eve_activate_ack_last(GtkWidget* w, gpointer ev)
{
Ev* ev = (Ev*)data;
......
......@@ -94,6 +94,7 @@ public:
static void eve_activate_print(GtkWidget* w, gpointer data);
static void ala_activate_print(GtkWidget* w, gpointer data);
static void blk_activate_print(GtkWidget* w, gpointer data);
static void eve_activate_export(GtkWidget* w, gpointer data);
static void eve_activate_ack_last(GtkWidget* w, gpointer data);
static void ala_activate_ack_last(GtkWidget* w, gpointer data);
static void ala_activate_ack_all(GtkWidget* w, gpointer data);
......
......@@ -122,6 +122,10 @@ HistGtk::HistGtk(void* hist_parent_ctx, GtkWidget* hist_parent_wid,
gtk_image_new_from_stock("gtk-print", GTK_ICON_SIZE_MENU));
g_signal_connect(file_print, "activate", G_CALLBACK(activate_print), this);
GtkWidget* file_export = gtk_image_menu_item_new_with_mnemonic(
CoWowGtk::translate_utf8("_Export"));
g_signal_connect(file_export, "activate", G_CALLBACK(activate_export), this);
GtkWidget* file_close = gtk_image_menu_item_new_with_mnemonic(
CoWowGtk::translate_utf8("_Close"));
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(file_close),
......@@ -132,6 +136,7 @@ HistGtk::HistGtk(void* hist_parent_ctx, GtkWidget* hist_parent_wid,
GtkMenu* file_menu = (GtkMenu*)g_object_new(GTK_TYPE_MENU, NULL);
gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_print);
gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_export);
gtk_menu_shell_append(GTK_MENU_SHELL(file_menu), file_close);
GtkWidget* file
......@@ -717,6 +722,13 @@ void HistGtk::activate_print(GtkWidget* w, gpointer data)
histOP->activate_print();
}
void HistGtk::activate_export(GtkWidget* w, gpointer data)
{
Hist* histOP = (Hist*)data;
histOP->activate_export();
}
void HistGtk::activate_zoom_in(GtkWidget* w, gpointer data)
{
Hist* histOP = (Hist*)data;
......
......@@ -92,6 +92,7 @@ public:
GtkWidget* w, GdkEvent* event, gpointer data);
static void activate_exit(GtkWidget* w, gpointer data);
static void activate_print(GtkWidget* w, gpointer data);
static void activate_export(GtkWidget* w, gpointer data);
static void activate_zoom_in(GtkWidget* w, gpointer data);
static void activate_zoom_out(GtkWidget* w, gpointer data);
static void activate_zoom_reset(GtkWidget* w, gpointer data);
......
......@@ -135,6 +135,7 @@ EvQt::EvQt(void* ev_parent_ctx, char* eve_name, char* ala_name, char* blk_name,
QMenu* file = menu_bar->addMenu(translate_utf8("&File"));
addMenuItem(object, file, "&Print", SLOT(eve_activate_print()), "",
"document-print");
addMenuItem(object, file, "&Export", SLOT(eve_activate_export()));
addMenuItem(
object, file, "&Close", SLOT(eve_activate_exit()), "CTRL+W", "window-close");
......@@ -687,6 +688,11 @@ void EvQtObject::blk_activate_print()
ev->blk_activate_print();
}
void EvQtObject::eve_activate_export()
{
ev->eve_activate_export();
}
void EvQtObject::eve_activate_ack_last()
{
ev->eve_activate_ack_last();
......
......@@ -99,6 +99,7 @@ public slots:
void eve_activate_print();
void ala_activate_print();
void blk_activate_print();
void eve_activate_export();
void eve_activate_ack_last();
void ala_activate_ack_last();
void ala_activate_ack_all();
......
......@@ -270,6 +270,48 @@ void Ev::blk_activate_print()
blk->print(title);
}
void Ev::eve_activate_export()
{
wow->CreateFileSelDia("Export", (void*)this,
eve_export_file_selected_cb, wow_eFileSelType_Tmp, wow_eFileSelAction_Save);
}
void Ev::eve_export_file_selected_cb(void *ctx, char *filename, wow_eFileSelType file_type)
{
((Ev *)ctx)->eve_export_events(filename);
}
int Ev::eve_export_events(const char *filename)
{
brow_tObject *list;
int list_cnt;
ItemAlarm *item;
char timstr[40];
char supobjectstr[80];
pwr_tFileName fname;
FILE *fp;
dcli_translate_filename(fname, filename);
fp = fopen(fname, "w");
if (!fp)
return 0;
fprintf(fp, "Time,Type,Prio,Text,Name,SupObject,Id,Status\n");
brow_GetObjectList(eve->brow->ctx, &list, &list_cnt);
for (int i = 0; i < list_cnt; i++) {
brow_GetUserData(list[i], (void **)&item);
time_AtoAscii(&item->time, time_eFormat_NumDateAndTime, timstr, sizeof(timstr));
strcpy(supobjectstr, cdh_ObjidToString(item->supobject.Objid, 1));
if (item->supobject.Flags.b.ObjectAttr)
sprintf(&supobjectstr[strlen(supobjectstr)], "#%u:%u", item->supobject.Offset,
item->supobject.Size);
fprintf(fp, "%s,%u,%lu,\"%s\",\"%s\",%s,\"(%u,%u)\",%u\n",
timstr, item->eventtype, item->eventprio, item->eventtext, item->eventname,
supobjectstr, item->eventid.Nix, item->eventid.Idx, item->status);
}
fclose(fp);
return 1;
}
void Ev::eve_activate_ack_last()
{
mh_sEventId* id;
......
......@@ -45,6 +45,9 @@
#ifndef xtt_eveve
#include "xtt_eveve.h"
#endif
#ifndef cow_wow
#include "cow_wow.h"
#endif
class CoWow;
class XttMethodToolbar;
......@@ -176,10 +179,12 @@ public:
char* name_to_alias(char* name);
pwr_tStatus set_view(pwr_tOid view);
void view_shift();
int eve_export_events(const char *filename);
void eve_activate_print();
void ala_activate_print();
void blk_activate_print();
void eve_activate_export();
void ala_activate_ack_last();
void eve_activate_ack_last();
void eve_activate_ack_all();
......@@ -210,6 +215,7 @@ public:
static void seve_copy_list_cb(void* ctx, EvList* evl);
static void seve_close_cb(void* ctx, EvEve* seve);
static void help_event_cb(void* ctx, void* item);
static void eve_export_file_selected_cb(void *ctx, char *filename, wow_eFileSelType file_type);
static pwr_tStatus mh_ack_bc(mh_sAck* MsgP);
static pwr_tStatus mh_return_bc(mh_sReturn* MsgP);
......
......@@ -148,6 +148,48 @@ void Hist::activate_print()
hist->print(Lng::translate("Eventlog"));
}
void Hist::activate_export()
{
wow->CreateFileSelDia("Export", (void*)this,
export_file_selected_cb, wow_eFileSelType_Tmp, wow_eFileSelAction_Save);
}
void Hist::export_file_selected_cb(void *ctx, char *filename, wow_eFileSelType file_type)
{
((Hist *)ctx)->export_events(filename);
}
int Hist::export_events(const char *filename)
{
brow_tObject *list;
int list_cnt;
ItemAlarm *item;
char timstr[40];
char supobjectstr[80];
pwr_tFileName fname;
FILE *fp;
dcli_translate_filename(fname, filename);
fp = fopen(fname, "w");
if (!fp)
return 0;
fprintf(fp, "Time,Type,Prio,Text,Name,SupObject,Id,Status\n");
brow_GetObjectList(hist->brow->ctx, &list, &list_cnt);
for (int i = 0; i < list_cnt; i++) {
brow_GetUserData(list[i], (void **)&item);
time_AtoAscii(&item->time, time_eFormat_NumDateAndTime, timstr, sizeof(timstr));
strcpy(supobjectstr, cdh_ObjidToString(item->supobject.Objid, 1));
if (item->supobject.Flags.b.ObjectAttr)
sprintf(&supobjectstr[strlen(supobjectstr)], "#%u:%u", item->supobject.Offset,
item->supobject.Size);
fprintf(fp, "%s,%u,%lu,\"%s\",\"%s\",%s,\"(%u,%u)\",%u\n",
timstr, item->eventtype, item->eventprio, item->eventtext, item->eventname,
supobjectstr, item->eventid.Nix, item->eventid.Idx, item->status);
}
fclose(fp);
return 1;
}
void Hist::activate_help()
{
if (help_cb)
......
......@@ -50,6 +50,9 @@ extern "C" {
#ifndef xtt_evlist
#include "xtt_evlist.h"
#endif
#ifndef cow_wow
#include "cow_wow.h"
#endif
#define ERROR_TIME_CONVERT -99
class CoWow;
......@@ -133,10 +136,12 @@ public:
}
void activate_print();
void activate_export();
void activate_help();
void activate_helpevent();
void time_cb(time_ePeriod period);
void stat();
int export_events(const char *filename);
static int GoBackMonth(
pwr_tTime TimeIn, pwr_tTime* FromTime, pwr_tTime* ToTime);
......@@ -154,6 +159,7 @@ public:
static void help_event_cb(void* ctx, void* item);
static void selection_changed_cb(void* ctx);
static void hist_init_cb(void* ctx);
static void export_file_selected_cb(void *ctx, char *filename, wow_eFileSelType file_type);
};
#else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment