Commit 628aa30e authored by Benoît Minisini's avatar Benoît Minisini

Take the other requested GUI components into account to choose the toolkit.

[INTERPRETER]
* NEW: Add a API to know if a native component exists on the disk.

[GB.GUI]
* BUG: Take the other requested GUI components into account to choose the toolkit.

[GB.GUI.QT]
* BUG: Take the other requested GUI components into account to choose the toolkit.
parent 0266ca1f
......@@ -83,6 +83,7 @@ const void *const GAMBAS_Api[] =
(void *)GB_Hook,
(void *)GB_LoadComponent,
(void *)COMPONENT_can_load_library,
(void *)COMPONENT_exist,
(void *)COMPONENT_is_loaded,
(void *)GB_CurrentComponent,
......
......@@ -181,18 +181,27 @@ bool COMPONENT_exist(const char *name)
return COMPONENT_find(name) != NULL;
}
bool COMPONENT_can_load_library(const char *name)
{
char *path;
path = FILE_buffer();
sprintf(path, LIB_PATTERN, COMPONENT_path, name);
return FILE_exist(path);
}
COMPONENT *COMPONENT_create(const char *name)
{
COMPONENT *comp;
char *path = NULL;
bool can_archive;
bool library = FALSE;
bool user_library = FALSE;
bool same_name_as_project = FALSE;
char *p = NULL;
if (*name == '/' || *name == ':') // user library
{
library = TRUE;
user_library = TRUE;
path = (char *)name;
if (*path == ':')
{
......@@ -219,7 +228,7 @@ COMPONENT *COMPONENT_create(const char *name)
if (p)
*p = ':';
if (library)
if (user_library)
{
comp->archive = ARCHIVE_create(comp->name, path);
comp->user = TRUE;
......@@ -259,24 +268,6 @@ COMPONENT *COMPONENT_create(const char *name)
if (!comp->library && !comp->archive && !same_name_as_project)
{
COMPONENT_delete(comp);
#if 0
// If gb.qt5 components are not present, automatically switch to gb.qt4 components
if (strncmp(name, "gb.qt5", 6) == 0 && (name[6] == 0 || name[6] == '.'))
{
char new_name[strlen(name) + 1];
if (name[6] == 0)
ERROR_warning("gb.qt5 not found, using gb.qt4 instead.");
strcpy(new_name, "gb.qt4");
strcat(new_name, &name[6]);
return COMPONENT_create(new_name);
}
#endif
THROW(E_LIBRARY, name, "cannot find component");
}
......
......@@ -64,6 +64,7 @@ void COMPONENT_delete(COMPONENT *comp);
COMPONENT *COMPONENT_find(const char *name);
bool COMPONENT_exist(const char *name);
bool COMPONENT_can_load_library(const char *name);
void COMPONENT_load(COMPONENT *comp);
void COMPONENT_unload(COMPONENT *comp);
......
......@@ -27,7 +27,7 @@
enum { USE_NOTHING, USE_GB_QT4, USE_GB_QT5 };
GB_INTERFACE GB EXPORT;
const GB_INTERFACE *GB_PTR EXPORT;
// Prevents gbi3 from complaining
......@@ -38,12 +38,51 @@ GB_DESC *GB_CLASSES[] EXPORT =
char *GB_INCLUDE EXPORT = "gb.qt4|gb.qt5";
const char *get_name(int use)
{
switch (use)
{
case USE_GB_QT4: return "gb.qt4";
default: return "gb.qt5";
}
}
static bool can_use(int use)
{
static const char *ext[] = { "ext", "webkit", "opengl", NULL };
char test[32];
char *suffix;
const char **pext;
const char *name;
name = get_name(use);
if (!GB.Component.CanLoadLibrary(name))
return FALSE;
strcpy(test, name);
suffix = test + strlen(name);
*suffix++ = '.';
for (pext = ext; *pext; pext++)
{
strcpy(suffix, *pext);
if (GB.Component.Exist(test) && !GB.Component.CanLoadLibrary(test))
return FALSE;
}
return TRUE;
}
int EXPORT GB_INIT(void)
{
int use = USE_NOTHING;
int use_other = USE_NOTHING;
char *env;
const char *comp;
const char *comp2;
env = getenv("GB_GUI");
if (env && *env)
......@@ -53,12 +92,12 @@ int EXPORT GB_INIT(void)
else if (strcmp(env, "gb.qt5") == 0)
use = USE_GB_QT5;
else
fprintf(stderr, "gb.gui: warning: '%s' component not supported\n", env);
fprintf(stderr, "gb.gui.qt: warning: '%s' component not supported\n", env);
}
if (use == USE_NOTHING)
{
use = USE_GB_QT4;
use = USE_GB_QT5;
env = getenv("KDE_FULL_SESSION");
......@@ -75,25 +114,37 @@ int EXPORT GB_INIT(void)
}
}
switch (use)
if (!can_use(use))
{
case USE_GB_QT4: comp = "gb.qt4"; break;
case USE_GB_QT5: comp = "gb.qt5"; break;
default: comp = "gb.qt5"; break;
}
if (GB.Component.Load(comp))
{
comp2 = use == USE_GB_QT5 ? "gb.qt4" : "gb.qt5";
if (GB.Component.Load(comp2))
if (use == USE_GB_QT4)
use_other = USE_GB_QT5;
else
use_other = USE_GB_QT4;
if (can_use(use_other))
{
fprintf(stderr, "gb.gui.qt: warning: '%s' component not found, using '%s' instead\n", get_name(use), get_name(use_other));
use = use_other;
}
else
{
fprintf(stderr, "gb.gui.qt: error: unable to find any QT component\n");
exit(1);
}
fprintf(stderr, "gb.gui: warning: '%s' component not found, using '%s' instead\n", comp, comp2);
comp = comp2;
}
comp = get_name(use);
if (GB.Component.Load(comp))
{
fprintf(stderr, "gb.gui.qt: error: cannot load component '%s'\n", comp);
exit(1);
}
else
{
env = getenv("GB_GUI_DEBUG");
if (env && !strcmp(env, "0"))
fprintf(stderr, "gb.gui.qt: loading '%s'\n", comp);
}
setenv("GB_GUI", comp, TRUE);
......@@ -105,4 +156,3 @@ void EXPORT GB_EXIT()
{
}
......@@ -28,7 +28,9 @@
#include "gb_common.h"
#ifndef __MAIN_C
extern GB_INTERFACE GB;
extern const GB_INTERFACE *GB_PTR;
#endif
#define GB (*GB_PTR)
#endif
......@@ -27,6 +27,13 @@
enum { USE_NOTHING, USE_GB_QT4, USE_GB_QT5, USE_GB_GTK, USE_GB_GTK3 };
static char use_list[4][3] = {
{ USE_GB_QT5, USE_GB_GTK, USE_GB_GTK3 },
{ USE_GB_QT4, USE_GB_GTK3, USE_GB_GTK },
{ USE_GB_GTK3, USE_GB_QT4, USE_GB_QT5 },
{ USE_GB_GTK, USE_GB_QT5, USE_GB_QT4 },
};
GB_INTERFACE GB EXPORT;
// Prevents gbi3 from complaining
......@@ -38,12 +45,54 @@ GB_DESC *GB_CLASSES[] EXPORT =
char *GB_INCLUDE EXPORT = "gb.qt4|gb.qt5|gb.gtk|gb.gtk3";
const char *get_name(int use)
{
switch (use)
{
case USE_GB_QT4: return "gb.qt4";
case USE_GB_QT5: return "gb.qt5";
case USE_GB_GTK3: return "gb.gtk3";
default: return "gb.gtk";
}
}
static bool can_use(int use)
{
static const char *ext[] = { "ext", "webkit", "opengl", NULL };
char test[32];
char *suffix;
const char **pext;
const char *name;
name = get_name(use);
if (!GB.Component.CanLoadLibrary(name))
return FALSE;
strcpy(test, name);
suffix = test + strlen(name);
*suffix++ = '.';
for (pext = ext; *pext; pext++)
{
strcpy(suffix, *pext);
if (GB.Component.Exist(test) && !GB.Component.CanLoadLibrary(test))
return FALSE;
}
return TRUE;
}
int EXPORT GB_INIT(void)
{
int use = USE_NOTHING;
int use_other = USE_NOTHING;
char *env;
const char *comp;
const char *comp2;
int i;
env = getenv("GB_GUI");
if (env)
......@@ -77,26 +126,42 @@ int EXPORT GB_INIT(void)
}
}
switch (use)
{
case USE_GB_QT4: comp = "gb.qt4"; break;
case USE_GB_QT5: comp = "gb.qt5"; break;
case USE_GB_GTK3: comp = "gb.gtk3"; break;
default: comp = "gb.gtk"; break;
}
if (GB.Component.Load(comp))
if (!can_use(use))
{
comp2 = (use == USE_GB_QT4 || use == USE_GB_QT5) ? "gb.gtk" : "gb.qt4";
if (GB.Component.Load(comp2))
use_other = USE_NOTHING;
for (i = 0; i <= 2; i++)
{
if (can_use(use_list[use - 1][i]))
{
use_other = use_list[use - 1][i];
break;
}
}
if (use_other)
{
fprintf(stderr, "gb.gui: warning: '%s' component not found, using '%s' instead\n", get_name(use), get_name(use_other));
use = use_other;
}
else
{
fprintf(stderr, "gb.gui: error: unable to find any GUI component\n");
exit(1);
}
fprintf(stderr, "gb.gui: warning: '%s' component not found, using '%s' instead\n", comp, comp2);
comp = comp2;
}
comp = get_name(use);
if (GB.Component.Load(comp))
{
fprintf(stderr, "gb.gui: error: cannot load component '%s'\n", comp);
exit(1);
}
else
{
env = getenv("GB_GUI_DEBUG");
if (env && !strcmp(env, "0"))
fprintf(stderr, "gb.gui: loading '%s'\n", comp);
}
setenv("GB_GUI", comp, TRUE);
......
......@@ -927,6 +927,7 @@ typedef
struct {
bool (*Load)(const char *);
bool (*CanLoadLibrary)(const char *);
bool (*Exist)(const char *);
bool (*IsLoaded)(const char *);
char *(*Current)(void);
......
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