Skip to content

Commit

Permalink
Started integrating the media files (images) into the sqlite database…
Browse files Browse the repository at this point in the history
… and made them available through the 'db_obtine_imagine_media_scalata' function. Also, the 'info form' now randomly loads a image file as it's main picture from a collection of 24 solar system pics stored in the database.
  • Loading branch information
3Nigma committed Jul 22, 2012
1 parent 71a9546 commit ec1e971
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 14 deletions.
Binary file modified src/psale/date.sqlite
Binary file not shown.
76 changes: 76 additions & 0 deletions src/psale/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,79 @@ db_obtine_versiune_curenta() {

return sqlite3_value_int(rez);
}

static const void *
db_obtine_blob(const char *numeTbl, const char *numeRes, int *dim) {
sqlite3_value *rez = NULL;
char afirmatie[255];
const void *deRet = NULL;

sprintf(afirmatie, "select Date from %s where Nume='%s'", numeTbl, numeRes);
rez = bd_obtine_rezultat_unic(PSALE_BD_NUME_FIS, afirmatie, 0);

deRet = sqlite3_value_blob(rez);
if(dim != NULL) (*dim) = sqlite3_value_bytes(rez);

return deRet;
}

static const void *
db_obtine_img_info_aleatoare(const char *numeTbl, int *dim) {
sqlite3_value *rez = NULL;
char afirmatie[255];
const void *deRet = NULL;

sprintf(afirmatie, "select Date from %s where Nume like 'fi_img_info_%%' order by random() limit 1", numeTbl);
rez = bd_obtine_rezultat_unic(PSALE_BD_NUME_FIS, afirmatie, 0);

deRet = sqlite3_value_blob(rez);
if(dim != NULL) (*dim) = sqlite3_value_bytes(rez);

return deRet;
}

GdkPixbuf *
db_obtine_imagine_media_scalata(db_media_type tp, gint w, gint h) {
GInputStream *memImg = NULL;
const void *vMem = NULL;
int dimMem = 0;

switch(tp) {
case DB_IMG_TUSCALE_LOGO:
vMem = db_obtine_blob(TB_NUME_TABEL_MEDIA, "fp_img_logo_tuscale_ale", &dimMem);
break;
case DB_IMG_COLAPSEAZA:
vMem = db_obtine_blob(TB_NUME_TABEL_MEDIA, "fc_img_bt_icoana_colapseaza", &dimMem);
break;
case DB_IMG_EXPANDEAZA:
vMem = db_obtine_blob(TB_NUME_TABEL_MEDIA, "fc_img_bt_icoana_expandeaza", &dimMem);
break;
case DB_IMG_EEPROM:
vMem = db_obtine_blob(TB_NUME_TABEL_MEDIA, "fc_img_bt_icoana_eeprom", &dimMem);
break;
case DB_IMG_PARASESTE:
vMem = db_obtine_blob(TB_NUME_TABEL_MEDIA, "fc_img_bt_icoana_paraseste_formular", &dimMem);
break;
case DB_IMG_REIA_COD:
vMem = db_obtine_blob(TB_NUME_TABEL_MEDIA, "fp_img_bt_icoana_reia_cod", &dimMem);
break;
case DB_IMG_SALVEAZA_COD:
vMem = db_obtine_blob(TB_NUME_TABEL_MEDIA, "fp_img_bt_icoana_salveaza_cod", &dimMem);
break;
case DB_IMG_TRIMITE_LA_ALE:
vMem = db_obtine_blob(TB_NUME_TABEL_MEDIA, "fp_img_bt_icoana_trimite_la_ale", &dimMem);
break;
case DB_IMG_LICENTA:
vMem = db_obtine_blob(TB_NUME_TABEL_MEDIA, "fi_img_licenta", &dimMem);
break;
case DB_IMG_INFO:
vMem = db_obtine_img_info_aleatoare(TB_NUME_TABEL_MEDIA, &dimMem);
break;
default:
/* nu ar trebui să ajungem aici */
break;
}
memImg = g_memory_input_stream_new_from_data(vMem, dimMem, NULL);

return gdk_pixbuf_new_from_stream_at_scale(memImg, w, h, FALSE, NULL, NULL);
}
17 changes: 17 additions & 0 deletions src/psale/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@
#include <sqlite3.h>

#define PSALE_BD_NUME_FIS "date.sqlite"
#define TB_NUME_TABEL_MEDIA "media"

typedef enum {
DB_IMG_TUSCALE_LOGO,
DB_IMG_COLAPSEAZA,
DB_IMG_EXPANDEAZA,
DB_IMG_EEPROM,
DB_IMG_PARASESTE,
DB_IMG_REIA_COD,
DB_IMG_SALVEAZA_COD,
DB_IMG_TRIMITE_LA_ALE,
DB_IMG_LICENTA,
DB_IMG_INFO
} db_media_type;

extern int
db_incarca_exemple_carte(GtkListStore *st);
Expand All @@ -19,4 +33,7 @@ db_obtine_adresa_actualizare();
extern int
db_obtine_versiune_curenta();

extern GdkPixbuf *
db_obtine_imagine_media_scalata(db_media_type tp, gint w, gint h);

#endif
23 changes: 14 additions & 9 deletions src/psale/fcod.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#endif

#include "al.h"
#include "db.h"
#include "fcod.h"

#define PSALE_CODS_IMPLICIT ".section text\n" \
Expand Down Expand Up @@ -111,12 +112,12 @@ btExpandatorActiuni_click(GtkWidget *bt, FormularCod *fc) {
switch(fc->vActiuni) {
case ASCUNSE:
gtk_widget_show(fc->cadruActiuni);
imgExpandatorPixBuf = gdk_pixbuf_new_from_file_at_size("media/bt_icoana_colapseaza.png", 20, 20, NULL);
imgExpandatorPixBuf = db_obtine_imagine_media_scalata(DB_IMG_COLAPSEAZA, 20, 20);
fc->vActiuni = VIZIBILE;
break;
case VIZIBILE:
gtk_widget_hide(fc->cadruActiuni);
imgExpandatorPixBuf = gdk_pixbuf_new_from_file_at_size("media/bt_icoana_expandeaza.png", 20, 20, NULL);
imgExpandatorPixBuf = db_obtine_imagine_media_scalata(DB_IMG_EXPANDEAZA, 20, 20);
fc->vActiuni = ASCUNSE;
break;
}
Expand Down Expand Up @@ -226,8 +227,7 @@ fc_initializeaza(Limbaj lmDorit, const char *codInitial, gchar *denumireSursa, g
btGestioneazaActiuni = gtk_button_new();
gtk_button_set_relief(GTK_BUTTON(btGestioneazaActiuni), GTK_RELIEF_NONE);
gtk_button_set_focus_on_click(GTK_BUTTON(btGestioneazaActiuni), FALSE);
GdkPixbuf *imgExpandatorPixBuf = gdk_pixbuf_new_from_file_at_size(esteExemplu ? "media/bt_icoana_colapseaza.png" : "media/bt_icoana_expandeaza.png",
20, 20, NULL);
GdkPixbuf *imgExpandatorPixBuf = db_obtine_imagine_media_scalata(esteExemplu ? DB_IMG_COLAPSEAZA : DB_IMG_EXPANDEAZA, 20, 20);
GtkWidget *imgExpandatorActiuni = gtk_image_new_from_pixbuf(imgExpandatorPixBuf);
gtk_button_set_image(GTK_BUTTON(btGestioneazaActiuni), imgExpandatorActiuni);
gtk_table_attach(GTK_TABLE(cadruFrm), btGestioneazaActiuni, 1, 2, 0, 2, GTK_SHRINK, GTK_FILL, 0, 0);
Expand All @@ -236,39 +236,44 @@ fc_initializeaza(Limbaj lmDorit, const char *codInitial, gchar *denumireSursa, g
btIncarcaPeAle = gtk_button_new_with_label("Încarcă pe Ale");
gtk_button_set_focus_on_click(GTK_BUTTON(btIncarcaPeAle), FALSE);
gtk_widget_set_size_request(GTK_WIDGET(btIncarcaPeAle), -1, 60);
GtkWidget *imgIncarcaPeAle = gtk_image_new_from_pixbuf(gdk_pixbuf_new_from_file_at_size("media/bt_icoana_trimite_la_ale.png", 16, 16, NULL));
GdkPixbuf *imgIncarcaPeAlePixBuf = db_obtine_imagine_media_scalata(DB_IMG_TRIMITE_LA_ALE, 16, 16);
GtkWidget *imgIncarcaPeAle = gtk_image_new_from_pixbuf(imgIncarcaPeAlePixBuf);
gtk_button_set_image_position(GTK_BUTTON(btIncarcaPeAle), GTK_POS_RIGHT);
gtk_button_set_image(GTK_BUTTON(btIncarcaPeAle), imgIncarcaPeAle);

btSalveazaLucrul = gtk_button_new_with_label("Salvează lucrul");
gtk_button_set_relief(GTK_BUTTON(btSalveazaLucrul), GTK_RELIEF_NONE);
gtk_button_set_focus_on_click(GTK_BUTTON(btSalveazaLucrul), FALSE);
gtk_widget_set_size_request(GTK_WIDGET(btSalveazaLucrul), -1, 50);
GtkWidget *imgSalveazaLucrul = gtk_image_new_from_pixbuf(gdk_pixbuf_new_from_file_at_size("media/bt_icoana_salveaza.png", 16, 16, NULL));
GdkPixbuf *imgSalveazaLucrulPixBuf = db_obtine_imagine_media_scalata(DB_IMG_SALVEAZA_COD, 16, 16);
GtkWidget *imgSalveazaLucrul = gtk_image_new_from_pixbuf(imgSalveazaLucrulPixBuf);
gtk_button_set_image_position(GTK_BUTTON(btSalveazaLucrul), GTK_POS_LEFT);
gtk_button_set_image(GTK_BUTTON(btSalveazaLucrul), imgSalveazaLucrul);

btReiaLucrul = gtk_button_new_with_label("Reia cod");
gtk_button_set_relief(GTK_BUTTON(btReiaLucrul), GTK_RELIEF_NONE);
gtk_button_set_focus_on_click(GTK_BUTTON(btReiaLucrul), FALSE);
gtk_widget_set_size_request(GTK_WIDGET(btReiaLucrul), -1, 40);
GtkWidget *imgReiaLucrul = gtk_image_new_from_pixbuf(gdk_pixbuf_new_from_file_at_size("media/bt_icoana_reia.png", 16, 16, NULL));
GdkPixbuf *imgReiaLucrulPixBuf = db_obtine_imagine_media_scalata(DB_IMG_REIA_COD, 16, 16);
GtkWidget *imgReiaLucrul = gtk_image_new_from_pixbuf(imgReiaLucrulPixBuf);
gtk_button_set_image_position(GTK_BUTTON(btReiaLucrul), GTK_POS_LEFT);
gtk_button_set_image(GTK_BUTTON(btReiaLucrul), imgReiaLucrul);

btCitesteEEPROM = gtk_button_new_with_label("Citește EEPROM");
gtk_button_set_relief(GTK_BUTTON(btCitesteEEPROM), GTK_RELIEF_NONE);
gtk_button_set_focus_on_click(GTK_BUTTON(btCitesteEEPROM), FALSE);
gtk_widget_set_size_request(GTK_WIDGET(btCitesteEEPROM), -1, 35);
GtkWidget *imgCitesteEEPROM = gtk_image_new_from_pixbuf(gdk_pixbuf_new_from_file_at_size("media/bt_icoana_eeprom.png", 16, 16, NULL));
GdkPixbuf *imgCitesteEEPROMPixBuf = db_obtine_imagine_media_scalata(DB_IMG_EEPROM, 16, 16);
GtkWidget *imgCitesteEEPROM = gtk_image_new_from_pixbuf(imgCitesteEEPROMPixBuf);
gtk_button_set_image_position(GTK_BUTTON(btCitesteEEPROM), GTK_POS_LEFT);
gtk_button_set_image(GTK_BUTTON(btCitesteEEPROM), imgCitesteEEPROM);

btParasesteFrm = gtk_button_new_with_label("Părăsește formular");
gtk_button_set_relief(GTK_BUTTON(btParasesteFrm), GTK_RELIEF_HALF);
gtk_button_set_focus_on_click(GTK_BUTTON(btParasesteFrm), FALSE);
gtk_widget_set_size_request(GTK_WIDGET(btParasesteFrm), -1, 30);
GtkWidget *imgParasesteFrm = gtk_image_new_from_pixbuf(gdk_pixbuf_new_from_file_at_size("media/bt_icoana_paraseste.png", 16, 16, NULL));
GdkPixbuf *imgParasesteFrmPixBuf = db_obtine_imagine_media_scalata(DB_IMG_PARASESTE, 16, 16);
GtkWidget *imgParasesteFrm = gtk_image_new_from_pixbuf(imgParasesteFrmPixBuf);
gtk_button_set_image_position(GTK_BUTTON(btParasesteFrm), GTK_POS_LEFT);
gtk_button_set_image(GTK_BUTTON(btParasesteFrm), imgParasesteFrm);

Expand Down
2 changes: 1 addition & 1 deletion src/psale/finfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ initializeaza_formular_info() {
incarca_info_general(cadruFrm);

/* inițializăm imaginea de informație */
imgInfo = gtk_image_new_from_file("media/info_img.png");
imgInfo = gtk_image_new_from_pixbuf(db_obtine_imagine_media_scalata(DB_IMG_INFO, -1, -1));
gtk_table_attach_defaults(GTK_TABLE(cadruFrm), imgInfo, 0, 1, 0, 1);

/* inițializăm butonul de părăsire a formularului */
Expand Down
6 changes: 2 additions & 4 deletions src/psale/fprin.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
static gboolean estePlacutaConectata;
static gboolean dlgCodForteazaActualizConex;
static GSList *listaDlgCod = NULL;
static GtkWidget *dlgInfo = NULL;

static void
placuta_sa_deconectat() {
Expand Down Expand Up @@ -96,8 +95,7 @@ cmbxCodCarte_selectat(GtkComboBox *widget, gpointer user_data) {

static void
btInfo_click(GtkWidget *widget, gpointer data) {
if(dlgInfo == NULL)
dlgInfo = initializeaza_formular_info();
GtkWidget *dlgInfo = initializeaza_formular_info();

gtk_widget_show_all(dlgInfo);
}
Expand Down Expand Up @@ -202,7 +200,7 @@ fp_initializeaza_formular_principal() {
gtk_container_add(GTK_CONTAINER(frm), cadruFormPrincipal);

/* inițializăm logoul aplicației */
imgLogo = gtk_image_new_from_file("media/tuscale_small_logo_ale.png");
imgLogo = gtk_image_new_from_pixbuf(db_obtine_imagine_media_scalata(DB_IMG_TUSCALE_LOGO, -1, -1));

/* inițializăm cadrul pentru logoul aplicației */
cadruImgLogo = gtk_event_box_new();
Expand Down

0 comments on commit ec1e971

Please sign in to comment.