legacy/experimental/ecdb/trunk/src/ecdb_burn_image_gui.c

325 lines
11 KiB
C
Raw Normal View History

/* vim: set sw=3 ts=3 sts=3 expandtab: */
#include "ecdb.h"
static void _button_cb_return(void *data, Evas_Object *obj,
2009-01-25 01:17:06 +00:00
const char *emission,
const char *source);
static void _button_cb_begin(void *data, Evas_Object *obj,
const char *emission,
const char *source);
static void _combo_cb_clicked(void *data, Evas_Object *obj,
const char *emission,
const char *source);
2009-02-05 04:11:22 +00:00
static void _page_hide_finished(void *data, Evas_Object *o,
const char *emission,
const char *source);
static void _page_del(void *data, Evas *e, Evas_Object *obj, void *ev);
static void
_page_del(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj,
void *ev __UNUSED__)
{
Ecdb_Image_Project *proj;
proj = evas_object_data_get(obj, "proj");
if (proj)
ecdb_image_project_destroy(proj);
}
static void
2009-02-05 04:11:22 +00:00
_page_hide_finished(void *data, Evas_Object *o, const char *emission __UNUSED__,
const char *source __UNUSED__)
{
2009-01-25 01:17:06 +00:00
Evas_Object *gui;
gui = data;
2009-02-05 04:11:22 +00:00
edje_object_part_unswallow(gui, o);
evas_object_hide(o);
}
static void
_button_cb_return(void *data, Evas_Object *obj,
const char *emission __UNUSED__,
const char *source __UNUSED__)
{
Ecdb_Page *page;
2009-02-05 04:11:22 +00:00
page = data;
edje_object_part_text_set(page->image, "progress_text", "Begin Burn");
edje_object_part_text_set(page->image, "progress_percent", "0%");
edje_object_signal_emit(page->image, "ecdb,burn_image_page,hide", "ecdb");
ecdb_welcome_page_show(page);
/* Hide the filelist to be nice */
2009-02-05 04:11:22 +00:00
edje_object_signal_emit(page->gui, "ecdb,filelist,hide", "ecdb");
}
static void
2009-02-05 04:11:22 +00:00
_button_cb_begin(void *data, Evas_Object *obj __UNUSED__,
2009-01-25 01:17:06 +00:00
const char *emission __UNUSED__,
const char *source __UNUSED__)
{
2009-02-05 04:11:22 +00:00
Ecdb_Image_Project *proj;
Ecdb_Page *page;
Ecdb_Source *iso_file;
char *file, *buf;
Ecdb_Burn_Result burn_result;
2009-02-05 04:11:22 +00:00
int drive, speed, idx;
2009-02-05 04:11:22 +00:00
page = data;
proj = evas_object_data_get(page->image, "proj");
file = ecdb_entry_text_get(proj->entry);
// Make sure that file actually exists
if (!ecore_file_exists(file))
{
2009-02-05 04:11:22 +00:00
edje_object_part_text_set(page->image, "progress_text", "File doesn't "
"exists!");
FREE(file);
return;
}
iso_file = ecdb_source_new();
ecdb_source_data_set(iso_file, file);
FREE(file);
2009-02-05 04:11:22 +00:00
ecdb_source_child_append(ECDB_BURN(proj)->files, iso_file);
2009-02-05 04:11:22 +00:00
drive = ecdb_combo_selected_get(ECDB_PROJECT(proj)->drive_combo);
if (drive < 0)
{
EINA_ERROR_PDBG("Choose a drive!\n");
2009-02-05 04:11:22 +00:00
edje_object_part_text_set(page->image, "progress_text",
"Choose a Drive!");
return;
}
speed = ecdb_speed_convert(eina_list_nth(em->drives, drive),
2009-02-05 04:11:22 +00:00
ecdb_combo_selected_get(ECDB_BURN(proj)->speed_combo));
if (speed < 0)
2009-02-05 04:11:22 +00:00
ECDB_BURN(proj)->speed = 0;
else
2009-02-05 04:11:22 +00:00
ECDB_BURN(proj)->speed = speed;
if (!ecdb_set_project_drive(ECDB_PROJECT(proj), drive))
{
EINA_ERROR_PWARN("Drive index doesn't exist!\n");
edje_object_part_text_set(page->image, "progress_text",
"Drive index doesn't exist!");
return;
}
if (!ECDB_PROJECT(proj)->drive->fresh_info)
{
EINA_ERROR_PDBG("Insert a disc into the drive!\n");
edje_object_part_text_set(page->image, "progress_text",
"Insert a disc into the drive!");
return;
}
if (!(ECDB_PROJECT(proj)->drive->status & ECDB_DISC_BLANK))
{
EINA_ERROR_PDBG("Insert a blank disc!\n");
edje_object_part_text_set(page->image, "progress_text",
"Insert a blank disc!");
return;
}
if (!ecdb_aquire_drive(ECDB_PROJECT(proj)))
{
EINA_ERROR_PWARN("Couldn't grab drive!\n");
2009-02-05 04:11:22 +00:00
edje_object_part_text_set(page->image, "progress_text",
"Couldn't grab the drive!");
return;
}
edje_object_part_text_set(page->image, "progress_text", "Commencing...");
2009-02-17 22:48:11 +00:00
burn_result = ecdb_burn_project(ECDB_BURN(proj), page);
switch (burn_result)
{
case ECDB_ERROR_NONE:
2009-02-05 04:11:22 +00:00
edje_object_signal_emit(page->gui, "ecdb,filelist,hide", "ecdb");
edje_object_signal_emit(page->image, "ecdb,burn_image,start", "ecdb");
Evas_Object *objs[] = {proj->entry, ECDB_PROJECT(proj)->ret,
ECDB_PROJECT(proj)->begin, ECDB_PROJECT(proj)->drive_combo,
ECDB_BURN(proj)->speed_combo, NULL};
for (idx = 0; objs[idx]; idx++)
2009-02-05 04:11:22 +00:00
edje_object_signal_emit(objs[idx], "ecdb,disable", "ecdb");
return;
case ECDB_ERROR_IMAGE_CREATE:
buf = "Invalid file!";
break;
case ECDB_ERROR_SOURCE_ATTACH:
buf = "Couldn't attach source data!";
break;
case ECDB_ERROR_WRITE_MODE:
buf = "No suitable burn mode!";
break;
default:
buf = "Unknown error :-(";
}
2009-02-05 04:11:22 +00:00
edje_object_part_text_set(page->image, "progress_text", buf);
burn_drive_release(ECDB_PROJECT(proj)->drive->tangible[0].drive, 0);
2009-02-05 04:11:22 +00:00
burn_drive_info_free(ECDB_PROJECT(proj)->drive->tangible);
}
static void
_combo_cb_clicked(void *data, Evas_Object *obj __UNUSED__,
const char *emission __UNUSED__,
const char *source __UNUSED__)
{
2009-02-05 04:11:22 +00:00
Evas_Object *b;
Ecdb_Burn_Project *bp;
Ecdb_Drive_Info *drive;
int sel, i, num_speeds;
char buf[1024];
2009-02-05 04:11:22 +00:00
bp = data;
sel = ecdb_combo_selected_get(ECDB_PROJECT(bp)->drive_combo);
if (sel < 0)
return;
ECDB_PROJECT(bp)->drive = drive = eina_list_nth(em->drives, sel);
/* Don't keep adding items to the combo if the drive hasn't changed */
if (drive == ecdb_combo_data_get(bp->speed_combo))
return;
num_speeds = drive->write_speeds[0];
2009-02-05 04:11:22 +00:00
ecdb_combo_data_set(bp->speed_combo, drive);
for (i = 1; i < num_speeds; i++)
{
if ((drive->write_speeds[i]) <= 0)
continue;
2009-02-05 04:11:22 +00:00
b = ecdb_combo_item_add(bp->speed_combo, NULL);
snprintf(buf, sizeof(buf), "%dkb/s", drive->write_speeds[i]);
ecdb_combo_item_label_set(b, buf);
2009-02-05 04:11:22 +00:00
ecdb_combo_append(bp->speed_combo, b);
evas_object_show(b);
}
}
void
2009-02-05 04:11:22 +00:00
ecdb_burn_image_page_show(Ecdb_Page *page)
{
2009-02-05 04:11:22 +00:00
if (!page->image)
{
2009-02-05 04:11:22 +00:00
Evas_Object *b;
Eina_List *l;
Ecdb_Drive_Info *drive;
Evas_Coord x, y, w, h;
2009-02-05 04:11:22 +00:00
Ecdb_Image_Project *proj;
Ecdb_Project *bp;
Ecdb_Burn_Project *bup;
/* Create the swallow */
page->image = edje_object_add(ecore_evas_get(em->main_win_ee));
edje_object_file_set(page->image, em->theme_path, "ecdb/burn_image_page");
edje_object_part_geometry_get(page->gui, "active_area", &x, &y, &w, &h);
evas_object_move(page->gui, x, y);
evas_object_resize(page->image, w, h);
edje_object_part_swallow(page->gui, "action_area", page->image);
evas_object_event_callback_add(page->image, EVAS_CALLBACK_DEL, _page_del,
page);
2009-02-05 04:11:22 +00:00
edje_object_signal_callback_add(page->image, "hide,finished",
"burn_image_page",
2009-02-05 04:11:22 +00:00
_page_hide_finished, page->gui);
evas_object_show(page->image);
/* Make the project */
proj = ecdb_image_project_new();
bp = ECDB_PROJECT(proj);
bup = ECDB_BURN(proj);
evas_object_data_set(page->image, "proj", proj);
/* Make the interface all nice and proper */
bp->ret = ecdb_button_add(page->image, "ecdb/burn_image/return");
ecdb_button_label_set(bp->ret, "Return to Main Page");
edje_object_signal_callback_add(page->image, "ecdb,clicked",
2009-02-05 04:11:22 +00:00
"ecdb/burn_image/return", _button_cb_return, page);
evas_object_show(bp->ret);
ecdb_button_icon_set(bp->ret, "ecdb/burn_image/return");
bp->begin = ecdb_button_add(page->image, "ecdb/burn_image/begin");
ecdb_button_label_set(bp->begin, "Start Burn");
edje_object_signal_callback_add(page->image, "ecdb,clicked",
2009-02-05 04:11:22 +00:00
"ecdb/burn_image/begin", _button_cb_begin, page);
evas_object_show(bp->begin);
ecdb_button_icon_set(bp->begin, "ecdb/burn_image/begin");
proj->entry = ecdb_entry_add(page->image, "ecdb/burn_image/file");
ecdb_entry_text_set(proj->entry, "Burn File");
evas_object_show(proj->entry);
bp->drive_combo = ecdb_combo_add(page->image, "ecdb/burn_image/drive");
ecdb_combo_header_set(bp->drive_combo, "Drive");
ecdb_combo_header_create_set(bp->drive_combo,
ecdb_gui_combo_header_from_drive);
evas_object_show(bp->drive_combo);
bup->speed_combo = ecdb_combo_add(page->image, "ecdb/burn_image/speed");
ecdb_combo_header_create_set(bup->speed_combo,
ecdb_gui_combo_header_from_speeds);
ecdb_combo_header_set(bup->speed_combo, "Max Speed");
evas_object_show(bup->speed_combo);
EINA_LIST_FOREACH(em->drives, l, drive)
{
2009-02-05 04:11:22 +00:00
b = ecdb_combo_item_add(bp->drive_combo, NULL);
ecdb_combo_item_label_set(b, drive->product);
edje_object_signal_callback_add(b, "ecdb,clicked", "ecdb",
_combo_cb_clicked, proj);
2009-02-05 04:11:22 +00:00
ecdb_combo_append(bp->drive_combo, b);
evas_object_show(b);
}
}
2009-02-05 04:11:22 +00:00
else if (edje_object_part_swallow_get(page->gui, "action_area") !=
page->image)
{
2009-02-05 04:11:22 +00:00
edje_object_part_swallow(page->gui, "action_area", page->image);
evas_object_show(page->image);
}
2009-02-05 04:11:22 +00:00
edje_object_signal_emit(page->gui, "ecdb,burn_image_page,visible", "ecdb");
edje_object_signal_emit(page->image, "ecdb,burn_image_page,visible", "ecdb");
}
void
ecdb_burn_image_cleanup(Ecdb_Page *page)
2009-02-17 22:48:11 +00:00
{
Ecdb_Image_Project *proj;
int idx;
if (!page)
{
EINA_ERROR_PWARN("ecdb_burn_image_cleanup: NULL page!\n");
2009-02-17 22:48:11 +00:00
return;
}
proj = evas_object_data_get(page->image, "proj");
if (!proj)
{
EINA_ERROR_PWARN("ecdb_burn_image_cleanup: NULL proj!\n");
2009-02-17 22:48:11 +00:00
return;
}
Evas_Object *objs[] = {proj->entry, ECDB_PROJECT(proj)->ret,
ECDB_PROJECT(proj)->begin, ECDB_PROJECT(proj)->drive_combo,
ECDB_BURN(proj)->speed_combo, NULL};
2009-02-17 22:48:11 +00:00
for (idx = 0; objs[idx]; idx++)
edje_object_signal_emit(objs[idx], "ecdb,enable", "ecdb");
edje_object_part_text_set(page->image, "progress_text", "Burn Complete!");
2009-02-17 22:48:11 +00:00
edje_object_signal_emit(page->image, "ecdb,burn_image,done", "ecdb");
// Set project attributes back to normal
ecdb_entry_text_set(proj->entry, NULL);
}