Exemple #1
0
static gboolean
load_connection (NMSettingsPlugin *config,
                 const char *filename)
{
	SettingsPluginIfcfg *plugin = SETTINGS_PLUGIN_IFCFG (config);
	NMIfcfgConnection *connection;
	int dir_len = strlen (IFCFG_DIR);
	char *ifcfg_path;

	if (   strncmp (filename, IFCFG_DIR, dir_len) != 0
	    || filename[dir_len] != '/'
	    || strchr (filename + dir_len + 1, '/') != NULL)
		return FALSE;

	/* get the real ifcfg-path. This allows us to properly
	 * handle load command using a route-* file etc. */
	ifcfg_path = utils_detect_ifcfg_path (filename, FALSE);
	if (!ifcfg_path)
		return FALSE;

	connection = find_by_path (plugin, ifcfg_path);
	update_connection (plugin, NULL, ifcfg_path, connection, TRUE, NULL, NULL);
	if (!connection)
		connection = find_by_path (plugin, ifcfg_path);

	g_free (ifcfg_path);
	return (connection != NULL);
}
Exemple #2
0
static void
load_pages(const xmlNode *pages, form_element_t *parent)
{
    const xmlNode *items = find_by_path(pages, "ContainedItems");
    const xmlNode *p = find_by_path(pages, "Properties/PagesRepresentation");

    int pages_rep = PAGES_NO;
    if (p)
        if (p->children)
            if (p->children->content) {

                if (xstrcmp(p->children->content, "TabsOnTop") == 0)
                    pages_rep = PAGES_ON_TOP;
            }

    form_element_t P;
    P.widget = gtk_notebook_new();
    P.box = false;

    if (pages_rep == PAGES_NO)
        gtk_notebook_set_show_tabs(GTK_NOTEBOOK(P.widget), false);

    const xmlNode *cur_node = NULL;
    for (cur_node = items->children; cur_node; cur_node = cur_node->next) {
        if (is_oftype(cur_node, "Page")) {
            load_page(cur_node, &P);
        }
    }

    container_add(parent, P.widget);

}
Exemple #3
0
static void
load_page(const xmlNode *page, form_element_t *parent)
{
    const xmlChar *label = entry_title_ex(page, false);
    const xmlNode *p = find_by_path(page, "Properties/Grouping");

    int grouping = GROUPING_HORIZONTAL;
    const xmlChar *c_grouping = children_content(p);
    if (c_grouping)
        grouping = xstrcmp(c_grouping, "Horizontal") == 0
                ? GROUPING_HORIZONTAL
                : GROUPING_VERTICAL
        ;

    form_element_t P;
    P.widget = grouping == GROUPING_HORIZONTAL
        ? gtk_hbox_new(false, 0)
        : gtk_vbox_new(false, 0)
    ;
    P.box = true;

    p = find_by_path(page, "ContainedItems");
    if (p)
        load_form_elements(p->children, &P);

    GtkWidget *w_label = gtk_label_new(GTK_CHAR(label));

    gtk_notebook_append_page(GTK_NOTEBOOK(parent->widget), P.widget, w_label);
}
void QHiMDDetection::remove_himddevice(QString path)
{
    QHiMDDevice * dev = static_cast<QHiMDDevice *>(find_by_path(path));
    int i = dlist.indexOf(find_by_path(path));

    if(i < 0)
        return;

    if(dev->isOpen())
        dev->close();
    delete dev;
    dev = NULL;

    dlist.removeAt(i);
}
void QHiMDWinDetection::remove_himddevice(QString path)
{
    int index = -1;
    QHiMDDevice * dev = static_cast<QHiMDDevice *>(find_by_path(path));

    if (!dev)
        return;

    index = dlist.indexOf(dev);

    if(dev->isOpen())
        dev->close();

    if(dev->name() != "disc image")
    {
        if(dev->MdChange() != NULL)
            unregister_mediaChange((HDEVNOTIFY)dev->MdChange());
        if(dev->deviceHandle() != NULL)
             CloseHandle(dev->deviceHandle());
     }

    delete dev;
    dev = NULL;

    dlist.removeAt(index);

    emit deviceListChanged(dlist);
}
Exemple #6
0
static const xmlChar *
entry_title(const xmlNode *p)
{
    /* TODO: Решить вопрос с префиксами пространств имён v8: */
    p = find_by_path(p, "Properties/Title/item/content");
    return children_content(p);
}
Exemple #7
0
static void
load_table(const xmlNode *table, form_element_t *parent)
{
    form_element_t T;

    GtkWidget *scroll = gtk_scrolled_window_new(NULL, NULL);
    GtkTreeModel *model = create_tree_model(table);
    T.widget = gtk_tree_view_new_with_model(model);

    table_make_columns(table, GTK_TREE_VIEW(T.widget));
    gtk_container_add(GTK_CONTAINER(scroll), T.widget);

    {
        const xmlNode *pre = find_by_path(table, "PredefinedContainedItems");

        if (pre->children) {

            form_element_t vbox, pre_box;
            vbox.widget = gtk_vbox_new(false, 0);
            vbox.box = true;

            pre_box.widget = gtk_vbox_new(false, 0);
            pre_box.box = true;

            load_form_elements(pre->children, &pre_box);

            gtk_box_pack_start(GTK_BOX(vbox.widget), pre_box.widget, false, false, 0);
            gtk_box_pack_start(GTK_BOX(vbox.widget), scroll, true, true, 0);

            scroll = vbox.widget;
        }
    }

    container_add(parent, scroll);
}
Exemple #8
0
static void
load_command_bar_sub_menu_buttons(const xmlNode *menu, form_element_t *parent)
{
    const xmlNode *c = find_by_path(menu, "ContainedItems");

    for (c = c->children; c ; c = c->next) {

        if (is_oftype(c, "Button")) {

            const xmlChar *c_title = entry_title_ex(c, false);
            GtkWidget *mel = gtk_menu_item_new_with_label(GTK_CHAR(c_title));

            gtk_menu_shell_append(GTK_MENU_SHELL(parent->widget), mel);
        }

        if (is_oftype(c, "Buttons")) {

            form_element_t sm;
            sm.widget = gtk_menu_new();

            const xmlChar *c_title = entry_title_ex(c, false);
            GtkWidget *mel = gtk_menu_item_new_with_label(GTK_CHAR(c_title));

            load_command_bar_sub_menu_buttons(c, &sm);

            gtk_menu_item_set_submenu(GTK_MENU_ITEM(mel), sm.widget);

            gtk_menu_shell_append(GTK_MENU_SHELL(parent->widget), mel);
        }

    }
}
Exemple #9
0
static void
ifcfg_dir_changed (GFileMonitor *monitor,
                   GFile *file,
                   GFile *other_file,
                   GFileMonitorEvent event_type,
                   gpointer user_data)
{
	SettingsPluginIfcfg *plugin = SETTINGS_PLUGIN_IFCFG (user_data);
	char *path, *ifcfg_path;
	NMIfcfgConnection *connection;

	path = g_file_get_path (file);

	ifcfg_path = utils_detect_ifcfg_path (path, FALSE);
	_LOGD ("ifcfg_dir_changed(%s) = %d // %s", path, event_type, ifcfg_path ? ifcfg_path : "(none)");
	if (ifcfg_path) {
		connection = find_by_path (plugin, ifcfg_path);
		switch (event_type) {
		case G_FILE_MONITOR_EVENT_DELETED:
			if (connection)
				remove_connection (plugin, connection);
			break;
		case G_FILE_MONITOR_EVENT_CREATED:
		case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
			/* Update or new */
			update_connection (plugin, NULL, ifcfg_path, connection, TRUE, NULL, NULL);
			break;
		default:
			break;
		}
		g_free (ifcfg_path);
	}
	g_free (path);
}
Exemple #10
0
static void
load_form_element(const xmlNode *cur_node, form_element_t *parent)
{
    if (is_oftype(cur_node, "Group")) {
        const xmlNode *p = find_by_path(cur_node, "Properties/Type")->children;

        if (xstrcmp(p->content, "UsualGroup") == 0)
            load_usual_group(cur_node, parent);
    }

    if (is_oftype(cur_node, "Text")) {
        load_text_entry(cur_node, parent, false);
    }

    if (is_oftype(cur_node, "Input")) {
        load_input(cur_node, parent);
    }

    if (is_oftype(cur_node, "CheckBox")) {
        load_check_box(cur_node, parent);
    }

    if (is_oftype(cur_node, "Pages")) {
        load_pages(cur_node, parent);
    }

    if (is_oftype(cur_node, "Table")) {
        load_table(cur_node, parent);
    }

    if (is_oftype(cur_node, "CommandBar")) {
        load_command_bar(cur_node, parent);
    }

}
Exemple #11
0
static void
impl_ifcfgrh_get_ifcfg_details (SettingsPluginIfcfg *plugin,
                                GDBusMethodInvocation *context,
                                const char *in_ifcfg)
{
	NMIfcfgConnection *connection;
	NMSettingConnection *s_con;
	const char *uuid;
	const char *path;

	if (!g_path_is_absolute (in_ifcfg)) {
		g_dbus_method_invocation_return_error (context,
		                                       NM_SETTINGS_ERROR,
		                                       NM_SETTINGS_ERROR_INVALID_CONNECTION,
		                                       "ifcfg path '%s' is not absolute", in_ifcfg);
		return;
	}

	connection = find_by_path (plugin, in_ifcfg);
	if (   !connection
	    || nm_ifcfg_connection_get_unmanaged_spec (connection)
	    || nm_ifcfg_connection_get_unrecognized_spec (connection)) {
		g_dbus_method_invocation_return_error (context,
		                                       NM_SETTINGS_ERROR,
		                                       NM_SETTINGS_ERROR_INVALID_CONNECTION,
		                                       "ifcfg file '%s' unknown", in_ifcfg);
		return;
	}

	s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection));
	if (!s_con) {
		g_dbus_method_invocation_return_error (context,
		                                       NM_SETTINGS_ERROR,
		                                       NM_SETTINGS_ERROR_FAILED,
		                                       "unable to retrieve the connection setting");
		return;
	}

	uuid = nm_setting_connection_get_uuid (s_con);
	if (!uuid) {
		g_dbus_method_invocation_return_error (context,
		                                       NM_SETTINGS_ERROR,
		                                       NM_SETTINGS_ERROR_FAILED,
		                                       "unable to get the UUID");
		return;
	}

	path = nm_connection_get_path (NM_CONNECTION (connection));
	if (!path) {
		g_dbus_method_invocation_return_error (context,
		                                       NM_SETTINGS_ERROR,
		                                       NM_SETTINGS_ERROR_FAILED,
		                                       "unable to get the connection D-Bus path");
		return;
	}

	g_dbus_method_invocation_return_value (context,
	                                       g_variant_new ("(so)", uuid, path));
}
Exemple #12
0
static void
load_label(const xmlNode *text, form_element_t *parent)
{
    const xmlChar *label = entry_title_ex(text, false);
    form_element_t L;

    L.widget = gtk_label_new(GTK_CHAR(label));
    L.box = false;

    justify_element(L.widget, find_by_path(text, "Properties/HeaderHorizontalAlign"));

    container_add(parent, L.widget);
}
Exemple #13
0
static const xmlChar *
entry_title_ex(const xmlNode *p, bool attach_c)
{
    const xmlNode *e = find_by_path(p, "Properties/Title/item/content");
    const xmlChar *r = 0;

    if (e)
        r = children_content(e);

    if (r) {
        if (attach_c) {
            char *buf = malloc(strlen(CHAR(r)) + 3);
            sprintf(buf, "%s: ", r);
            r = XSTRING (g_strdup(buf));
            free(buf);
        }
        return r;
    }

    e = find_by_path(p, "Properties/Name");
    if (e)
        r = children_content(e);
    if (r) {

        char *buf = malloc(strlen(CHAR(r)) + 5);

        if (attach_c)
            sprintf(buf, "[%s]: ", r);
        else
            sprintf(buf, "[%s]", r);

        r = XSTRING (g_strdup(buf));
        free(buf);

        return r;
    }
    return 0;
}
static gboolean
load_connection (NMSystemConfigInterface *config,
                 const char *filename)
{
	SCPluginIfcfg *plugin = SC_PLUGIN_IFCFG (config);
	NMIfcfgConnection *connection;
	int dir_len = strlen (IFCFG_DIR);

	if (   strncmp (filename, IFCFG_DIR, dir_len) != 0
	    || filename[dir_len] != '/'
	    || strchr (filename + dir_len + 1, '/') != NULL)
		return FALSE;

	if (utils_should_ignore_file (filename + dir_len + 1, TRUE))
		return FALSE;

	connection = find_by_path (plugin, filename);
	update_connection (plugin, NULL, filename, connection, TRUE, NULL, NULL);
	if (!connection)
		connection = find_by_path (plugin, filename);

	return (connection != NULL);
}
void QHiMDWinDetection::add_himddevice(QString path, QString name)
{
    if (find_by_path(path))
        return;

    QHiMDDevice * new_device = new QHiMDDevice();
    int k;
    char drv[] = "\\\\.\\X:";
    QByteArray device = "\\\\.\\PHYSICALDRIVE";
    char file[] = "X:\\HI-MD.IND";
    DWORD retbytes;
    HANDLE hdev, dev;
    STORAGE_DEVICE_NUMBER sdn;
    OFSTRUCT OFfile;

    drv[4] = path.at(0).toLatin1();

    hdev = CreateFileA(drv, NULL , FILE_SHARE_READ, NULL,
                                           OPEN_EXISTING, 0, NULL);
    if(hdev == INVALID_HANDLE_VALUE)
        return;

    k = DeviceIoControl(hdev, IOCTL_STORAGE_GET_DEVICE_NUMBER, NULL, 0, &sdn, sizeof(sdn), &retbytes, NULL);
    CloseHandle(hdev);
    if(k != 0)
        device.append(QString::number(sdn.DeviceNumber));

    dev = CreateFileA(device.data(), NULL , FILE_SHARE_READ, NULL,
                                           OPEN_EXISTING, 0, NULL);
    if(dev == INVALID_HANDLE_VALUE)
        return;

    new_device->setDeviceHandle(dev);
    new_device->registerMdChange(register_mediaChange(new_device->deviceHandle()));
    new_device->setBusy(false);
    new_device->setPath(path);
    new_device->setName(name);

    file[0] = path.at(0).toLatin1();
    if(OpenFile(file, &OFfile, OF_EXIST) != HFILE_ERROR)
        new_device->setMdInserted(true);
    else
        new_device->setMdInserted(false);

    dlist.append(new_device);
    emit deviceListChanged(dlist);

    return;
}
Exemple #16
0
static void
load_command_bar_sub_menu(const xmlNode *menu, form_element_t *parent)
{
    const xmlChar *title = entry_title_ex(menu, false);
    GtkToolItem *submenu = gtk_menu_tool_button_new(NULL, GTK_CHAR(title));

    form_element_t m;
    m.widget = gtk_menu_new();

    const xmlNode *c = find_by_path(menu, "ContainedItems");
    for (c = c->children; c ; c = c->next) {

        if (is_oftype(c, "Button")) {
            const xmlChar *c_title = entry_title_ex(c, false);
            GtkWidget *mel = gtk_menu_item_new_with_label(GTK_CHAR(c_title));

            gtk_menu_shell_append(GTK_MENU_SHELL(m.widget), mel);
        }

        if (is_oftype(c, "Buttons")) {

            form_element_t sm;
            sm.widget = gtk_menu_new();

            const xmlChar *c_title = entry_title_ex(c, false);
            GtkWidget *mel = gtk_menu_item_new_with_label(GTK_CHAR(c_title));

            load_command_bar_sub_menu_buttons(c, &sm);

            gtk_menu_item_set_submenu(GTK_MENU_ITEM(mel), sm.widget);

            gtk_menu_shell_append(GTK_MENU_SHELL(m.widget), mel);
        }

    }

    gtk_menu_tool_button_set_menu(GTK_MENU_TOOL_BUTTON(submenu), m.widget);

    {
        /*! TODO: Выяснить, почему подменю не появляется,
            если его не добавить в видимое меню на форме
         */
        GtkWidget *mel = gtk_menu_item_new();
        gtk_menu_item_set_submenu(GTK_MENU_ITEM(mel), m.widget);
        gtk_menu_shell_append(GTK_MENU_SHELL(global_menu_bar), mel);
    }

    gtk_toolbar_insert(GTK_TOOLBAR(parent->widget), submenu, -1);
}
Exemple #17
0
static int
table_calc_columns_count(const xmlNode *table)
{
    const xmlNode *cur_node = NULL;
    int res = 0;
    for (cur_node = table->children; cur_node; cur_node = cur_node->next) {
        if (is_oftype(cur_node, "Text"))
            ++res;
        if (is_oftype(cur_node, "Input"))
            ++res;
        if (is_oftype(cur_node, "Columns"))
            res += table_calc_columns_count(find_by_path(cur_node, "ContainedItems"));
    }
    return res;
}
static void
ifcfg_dir_changed (GFileMonitor *monitor,
                   GFile *file,
                   GFile *other_file,
                   GFileMonitorEvent event_type,
                   gpointer user_data)
{
	SCPluginIfcfg *plugin = SC_PLUGIN_IFCFG (user_data);
	char *path, *base, *ifcfg_path;
	NMIfcfgConnection *connection;

	path = g_file_get_path (file);
	if (utils_should_ignore_file (path, FALSE)) {
		g_free (path);
		return;
	}

	_LOGD ("ifcfg_dir_changed(%s) = %d", path, event_type);

	base = g_file_get_basename (file);
	if (utils_is_ifcfg_alias_file (base, NULL)) {
		/* Alias file changed. Get the base ifcfg file from it */
		ifcfg_path = utils_get_ifcfg_from_alias (path);
	} else {
		/* Given any ifcfg, keys, or routes file, get the ifcfg file path */
		ifcfg_path = utils_get_ifcfg_path (path);
	}
	if (ifcfg_path) {
		connection = find_by_path (plugin, ifcfg_path);
		switch (event_type) {
		case G_FILE_MONITOR_EVENT_DELETED:
			if (connection)
				remove_connection (plugin, connection);
			break;
		case G_FILE_MONITOR_EVENT_CREATED:
		case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
			/* Update or new */
			update_connection (plugin, NULL, ifcfg_path, connection, TRUE, NULL, NULL);
			break;
		default:
			break;
		}
		g_free (ifcfg_path);
	}
	g_free (path);
	g_free (base);
}
Exemple #19
0
static GtkTreeModel *
create_tree_model(const xmlNode *table)
{
    const xmlNode *p = find_by_path(table, "ContainedItems");
    int columns_count = table_calc_columns_count(p);

    GType *_types = g_malloc_n(columns_count, sizeof(GType));
    int i = columns_count;
    while (i--)
        _types[i] = G_TYPE_STRING;

    GtkListStore *model = gtk_list_store_newv(columns_count, _types);

    g_free(_types);

    return GTK_TREE_MODEL(model);
}
    std::shared_ptr<Object<Impl>>
    Module_scanner<Impl>::create_object(ast::Variable_def const& node) {
      std::shared_ptr<Object<Impl>> obj(new Object<Impl>());

      // get name
      obj->name = dynamic_cast<ast::Identifier const&>(node.identifier()).identifier();
      if( m_mod.objects.count(obj->name) > 0 )
        throw std::runtime_error(std::string("Variable with name ")
            + obj->name
            + std::string(" already exists"));

      // get type
      if( typeid(node.type()) == typeid(ast::Qualified_name) ) {
        auto const& type_name = dynamic_cast<ast::Qualified_name const&>(node.type()).name();

        LOG4CXX_TRACE(this->m_logger, "qualified name of type: "
            << boost::algorithm::join(type_name, "::"));

        if( type_name.size() > 1 ) {
          obj->type = find_by_path(m_mod,
              &Module<Impl>::types,
              type_name);
        } else {
          obj->type = find_type(m_mod, type_name[0]);
        }
        if( !obj->type ) {
          std::stringstream strm;
          strm << node.type().location();
          std::string type_name_join = boost::algorithm::join(type_name, "::");
          strm << ": typename '" << type_name_join << "' not found.";
          throw std::runtime_error(strm.str());
        }
      } else if( typeid(node.type()) == typeid(ast::Array_type) ) {
        auto& ar_type = dynamic_cast<ast::Array_type const&>(node.type());

        obj->type = this->create_array_type(ar_type);
        m_mod.types[obj->type->name] = obj->type;
      } else {
        throw std::runtime_error("Unexpected type of type specification for variable definition.");
      }

      return obj;
    }
Exemple #21
0
static gboolean
load_connection (NMSystemConfigInterface *config,
                 const char *filename)
{
	SCPluginKeyfile *self = SC_PLUGIN_KEYFILE (config);
	NMKeyfileConnection *connection;
	int dir_len = strlen (KEYFILE_DIR);

	if (   strncmp (filename, KEYFILE_DIR, dir_len) != 0
	    || filename[dir_len] != '/'
	    || strchr (filename + dir_len + 1, '/') != NULL)
		return FALSE;

	if (nm_keyfile_plugin_utils_should_ignore_file (filename + dir_len + 1))
		return FALSE;

	connection = update_connection (self, NULL, filename, find_by_path (self, filename), TRUE, NULL, NULL);

	return (connection != NULL);
}
Exemple #22
0
static void
dir_changed (GFileMonitor *monitor,
             GFile *file,
             GFile *other_file,
             GFileMonitorEvent event_type,
             gpointer user_data)
{
	NMSystemConfigInterface *config = NM_SYSTEM_CONFIG_INTERFACE (user_data);
	SCPluginKeyfile *self = SC_PLUGIN_KEYFILE (config);
	NMKeyfileConnection *connection;
	char *full_path;
	gboolean exists;

	full_path = g_file_get_path (file);
	if (nm_keyfile_plugin_utils_should_ignore_file (full_path)) {
		g_free (full_path);
		return;
	}
	exists = g_file_test (full_path, G_FILE_TEST_EXISTS);

	nm_log_dbg (LOGD_SETTINGS, "dir_changed(%s) = %d; file %s", full_path, event_type, exists ? "exists" : "does not exist");

	connection = find_by_path (self, full_path);

	switch (event_type) {
	case G_FILE_MONITOR_EVENT_DELETED:
		if (!exists && connection)
			remove_connection (SC_PLUGIN_KEYFILE (config), connection);
		break;
	case G_FILE_MONITOR_EVENT_CREATED:
	case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
		if (exists)
			update_connection (SC_PLUGIN_KEYFILE (config), NULL, full_path, connection, TRUE, NULL, NULL);
		break;
	default:
		break;
	}

	g_free (full_path);
}
Exemple #23
0
static void
table_make_columns(const xmlNode *table, GtkTreeView *view)
{
    const xmlNode *p = find_by_path(table, "ContainedItems");
    const xmlNode *cur_node = NULL;

    for (cur_node = p->children; cur_node; cur_node = cur_node->next) {
        if (is_oftype(cur_node, "Text")) {
            const xmlChar *title = entry_title_ex(cur_node, false);
            GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
            GtkTreeViewColumn *c = gtk_tree_view_column_new_with_attributes (GTK_CHAR(title), renderer, NULL);
            gtk_tree_view_append_column(view, c);
        }
        if (is_oftype(cur_node, "Input")) {
            const xmlChar *title = entry_title_ex(cur_node, false);
            GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
            GtkTreeViewColumn *c = gtk_tree_view_column_new_with_attributes (GTK_CHAR(title), renderer, NULL);
            gtk_tree_view_append_column(view, c);
        }
        if (is_oftype(cur_node, "Columns"))
            table_make_columns(cur_node, view);
    }
}
Exemple #24
0
static void
load_command_bar(const xmlNode *bar, form_element_t *parent)
{
    const xmlNode *n = find_by_path(bar, "ContainedItems");

    form_element_t cbar;
    cbar.widget = gtk_toolbar_new();

    for (n = n->children; n ; n = n->next) {
        if (is_oftype(n, "Button")) {

            const xmlChar *title = entry_title_ex(n, false);
            GtkToolItem *btn = gtk_tool_button_new(NULL, GTK_CHAR(title));

            gtk_toolbar_insert(GTK_TOOLBAR(cbar.widget), btn, -1);
        }

        if (is_oftype(n, "SubMenu")) {
            load_command_bar_sub_menu(n, &cbar);
        }
    }

    container_add(parent, cbar.widget);
}
static gboolean
impl_ifcfgrh_get_ifcfg_details (SCPluginIfcfg *plugin,
                                const char *in_ifcfg,
                                const char **out_uuid,
                                const char **out_path,
                                GError **error)
{
	NMIfcfgConnection *connection;
	NMSettingConnection *s_con;
	const char *uuid;
	const char *path;

	if (!g_path_is_absolute (in_ifcfg)) {
		g_set_error (error,
		             NM_SETTINGS_ERROR,
		             NM_SETTINGS_ERROR_INVALID_CONNECTION,
		             "ifcfg path '%s' is not absolute", in_ifcfg);
		return FALSE;
	}

	connection = find_by_path (plugin, in_ifcfg);
	if (   !connection
	    || nm_ifcfg_connection_get_unmanaged_spec (connection)
	    || nm_ifcfg_connection_get_unrecognized_spec (connection)) {
		g_set_error (error,
		             NM_SETTINGS_ERROR,
		             NM_SETTINGS_ERROR_INVALID_CONNECTION,
		             "ifcfg file '%s' unknown", in_ifcfg);
		return FALSE;
	}

	s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection));
	if (!s_con) {
		g_set_error (error,
		             NM_SETTINGS_ERROR,
		             NM_SETTINGS_ERROR_FAILED,
		             "unable to retrieve the connection setting");
		return FALSE;
	}

	uuid = nm_setting_connection_get_uuid (s_con);
	if (!uuid) {
		g_set_error (error,
		             NM_SETTINGS_ERROR,
		             NM_SETTINGS_ERROR_FAILED,
		             "unable to get the UUID");
		return FALSE;
	}
	
	path = nm_connection_get_path (NM_CONNECTION (connection));
	if (!path) {
		g_set_error (error,
		             NM_SETTINGS_ERROR,
		             NM_SETTINGS_ERROR_FAILED,
		             "unable to get the connection D-Bus path");
		return FALSE;
	}

	*out_uuid = g_strdup (uuid);
	*out_path = g_strdup (path);

	return TRUE;
}
Exemple #26
0
void bg_db_update_files(bg_db_t * db, bg_db_scan_item_t * files, int num, int scan_flags,
                        int64_t scan_dir_id, const char * scan_dir)
  {
  char * sql;
  int result;
  bg_db_file_t * file;
  bg_db_dir_t * dir;
  
  int i;
  bg_db_scan_item_t * si;
  
  bg_sqlite_id_tab_t tab;
  bg_sqlite_id_tab_init(&tab);
  
  bg_log(BG_LOG_INFO, LOG_DOMAIN, "Getting directories from database");
  sql =
    sqlite3_mprintf("select ID from DIRECTORIES where SCAN_DIR_ID = %"PRId64";", scan_dir_id);
  result = bg_sqlite_exec(db->db, sql, bg_sqlite_append_id_callback, &tab);
  sqlite3_free(sql);

  bg_log(BG_LOG_INFO, LOG_DOMAIN, "Found %d directories in database", tab.num_val);

  for(i = 0; i < tab.num_val; i++)
    {
    dir = bg_db_object_query(db, tab.val[i]);

    if(!dir) // dir can be gone already if the parent directory vanished
      continue;
    
    if(!strcmp(dir->path, scan_dir))
      {
      bg_db_object_unref(dir);
      continue;
      }
    
    si = find_by_path(files, num, dir->path, BG_DB_DIRENT_DIRECTORY);
    if(!si)
      {
      bg_log(BG_LOG_INFO, LOG_DOMAIN,
             "Directory %s disappeared, removing from database", dir->path);
      bg_db_object_delete(db, dir);
      }
    else
      {
      bg_db_object_unref(dir);
      si->done = 1;
      }
    }

  bg_sqlite_id_tab_reset(&tab);
  bg_log(BG_LOG_INFO, LOG_DOMAIN, "Getting files from database");
  
  sql =
    sqlite3_mprintf("select ID from FILES where SCAN_DIR_ID = %"PRId64";", scan_dir_id);
  result = bg_sqlite_exec(db->db, sql, bg_sqlite_append_id_callback, &tab);
  sqlite3_free(sql);
  
  if(!result)
    goto fail;
  
  bg_log(BG_LOG_INFO, LOG_DOMAIN, "Found %d files in database", tab.num_val);

  for(i = 0; i < tab.num_val; i++)
    {
    file = bg_db_object_query(db, tab.val[i]);
    
    si = find_by_path(files, num, file->path, BG_DB_DIRENT_FILE);
    if(!si)
      {
      bg_log(BG_LOG_INFO, LOG_DOMAIN,
             "File %s disappeared, removing from database", file->path);
      bg_db_object_delete(db, file);
      }
    else if(si->mtime != file->mtime)
      {
      bg_log(BG_LOG_INFO, LOG_DOMAIN, 
             "File %s changed on disk, removing from database for re-adding later", file->path);
      bg_db_object_delete(db, file);
      }
    else
      {
      si->done = 1;
      bg_db_object_unref(file);
      }
    }

  bg_db_add_files(db, files, num, scan_flags, scan_dir_id);
  
  fail:
  bg_sqlite_id_tab_free(&tab);
  
  }
Exemple #27
0
static form_element_t *
read_83_form(const char *path)
{

    xmlDoc *doc = NULL;
    xmlNode *root_element = NULL;
    const xmlNode *el;

    doc = xmlReadFile(path, NULL, 0);
    root_element = xmlDocGetRootElement(doc);

    el = find_by_name(root_element->children, "Elements");

    int grouping = GROUPING_VERTICAL;

    {
        const xmlNode *p = find_by_path(el, "Properties/ChildrenGrouping")->children;

        if (xstrcmp(p->content, "Vertical") != 0)
            grouping = GROUPING_HORIZONTAL;
    }

    el = find_by_path(el, "ContainedItems");

    form_element_t *form = malloc(sizeof(*form));

    form->widget = grouping == GROUPING_HORIZONTAL
            ? gtk_hbox_new(false, 2)
            : gtk_vbox_new(false, 2)
    ;
    form->box = true;

    {
        const xmlNode *pre = find_by_name(root_element->children, "Elements");
        pre = find_by_path(pre, "PredefinedContainedItems");

        if (pre->children) {

            form_element_t vbox, pre_box;
            vbox.widget = gtk_vbox_new(false, 0);
            vbox.box = true;

            pre_box.widget = gtk_vbox_new(false, 0);
            pre_box.box = true;

            load_form_elements(pre->children, &pre_box);

            gtk_box_pack_start(GTK_BOX(vbox.widget), pre_box.widget, false, false, 0);
            gtk_box_pack_start(GTK_BOX(vbox.widget), form->widget, false, false, 0);

            form->widget = vbox.widget;
        }
    }

    load_form_elements(el->children, form);

    xmlFreeDoc(doc);

    xmlCleanupParser();

    return form;
}
    std::shared_ptr<Instantiation<Impl>>
    Module_scanner<Impl>::create_instantiation(ast::Module_instantiation const& node) {
      std::shared_ptr<Instantiation<Impl>> inst(new Instantiation<Impl>);
      std::string module_name;

      inst->name = dynamic_cast<ast::Identifier const&>(node.instance_name()).identifier();
      if( m_mod.instantiations.count(inst->name) > 0 )
        throw std::runtime_error(std::string("Instantiation with name ")
            + inst->name
            + std::string(" already exists"));

      if( node.is_template_instantiation() ) {
        LOG4CXX_TRACE(Namespace_scanner<Impl>::m_logger, "instantiating module template");
        // extract name
        auto tmpl_id = node.template_identifier();
        std::vector<Label> qname = tmpl_id.name();
        std::string qname_join = boost::algorithm::join(qname, "::");

        // find template
        std::shared_ptr<Module_template<Impl>> tmpl;
        if( qname.size() > 1 ) {
          tmpl = find_by_path(m_mod,
              &Module<Impl>::module_templates,
              qname);
        } else {
          tmpl = find_module_template(m_mod, qname[0]);
        }

        if( !tmpl ) {
          std::stringstream strm;
          strm << "Can not find module template with name '"
            << qname_join
            << "'";
          throw std::runtime_error(strm.str());
        }

        // determine module name and type overrides
        module_name = qname_join + '<';
        auto type_names = tmpl_id.arg_type_names();
        std::map<Label,std::shared_ptr<Type<Impl>>> types;
        auto it_placeholder = tmpl->type_names.begin();
        for(auto it=type_names.begin();
            (it != type_names.end()) && (it_placeholder != tmpl->type_names.end()); ) {
          // find type
          auto ty = find_type(m_mod, *it);
          if( !ty ) {
            std::stringstream strm;
            strm << node.location() << ": "
              << "failed to find type '"
              << *it
              << "' in instantiation of template '"
              << qname_join
              << "'";
            throw std::runtime_error(strm.str());
          }
          types[*it_placeholder] = ty;

          // append name
          module_name += *it;
          if( ++it != type_names.end() )
            module_name += ',';
          ++it_placeholder;
        }
        module_name += '>';

        // run Module_scanner
        inst->module = this->instantiate_module_template(module_name,
            tmpl->module_node,
          types);
    } else {
      if( typeid(node.module_name()) == typeid(ast::Qualified_name) ) {
        auto const& qn = dynamic_cast<ast::Qualified_name const&>(node.module_name()).name();
        if( qn.size() > 1 ) {
          inst->module = find_by_path(m_mod,
              &Module<Impl>::modules,
              qn);
        } else {
          inst->module = find_module(m_mod, qn[0]);
        }
      } else {
        std::stringstream strm;
        strm << node.location()
          << "Expecting a qualified name as module for now ("
          << __func__
          << ")";
        throw std::runtime_error(strm.str());
      }
    }

    if( !inst->module ) {
      std::stringstream strm;
      strm << node.location();
      strm << ": module '" << module_name << "' not found.";
      throw std::runtime_error(strm.str());
    }

    std::set<Label> matched_ports;
    for(auto& i : node.connection_items()) {
      if( typeid(*i) == typeid(ast::Connection_item) ) {
        auto& con_item = dynamic_cast<ast::Connection_item const&>(*i);
        auto port_name = con_item.port_name().identifier();
        //auto signal_name = con_item.signal_name().identifier();

        if( matched_ports.count(port_name) > 0 ) {
          std::stringstream strm;
          strm << con_item.port_name().location();
          strm << ": Port already connected";
          throw std::runtime_error(strm.str());
        }

        std::shared_ptr<Port_assignment<Impl>> port_assign(new Port_assignment<Impl>());
        port_assign->port = find_port(*(inst->module), port_name);
        if( !port_assign->port ) {
          std::stringstream strm;
          strm << con_item.port_name().location();
          strm << ": port '" << port_name << "' not found.";
          throw std::runtime_error(strm.str());
        }

        //port_assign->object = find_object(m_mod, signal_name);
        //if( !port_assign->object ) {
          //std::stringstream strm;
          //strm << con_item.signal_name().location();
          //strm << ": assigned object '" << signal_name << "' not found.";
          //throw std::runtime_error(strm.str());
        //}

        //if( !type_compatible(*(port_assign->port->type), *(port_assign->object->type)) ) {
          //std::stringstream strm;
          //strm << con_item.location();
          //strm << ": incompatible types in port assignment: expected type '"
            //<< *(port_assign->port->type)
            //<< "' got '"
            //<< *(port_assign->object->type) << "'";
          //throw std::runtime_error(strm.str());
        //}

        inst->connection.push_back(port_assign);
        matched_ports.insert(port_name);
      } else if( typeid(*i) == typeid(ast::Identifier) ) {
        auto& obj_name = dynamic_cast<ast::Identifier const&>(*i).identifier();
        auto assignee = find_object(m_mod, obj_name);

        if( !assignee ) {
          std::stringstream strm;
          strm << i->location()
            << ": object '" << obj_name << "' not found";
          throw std::runtime_error(strm.str());
        }

        auto assignee_socket = find_socket(m_mod, assignee->type->name);
        if( !assignee_socket ) {
          std::stringstream strm;
          strm << i->location()
            << ": object '" << obj_name << "' of type '" << assignee->type->name
            << "' is not a socket";
          throw std::runtime_error(strm.str());
        }

        for(auto assignee_port_pair : assignee_socket->elements) {
          auto port_name = assignee_port_pair.first;
          auto assignee_port = assignee_port_pair.second;
          auto searchit = assignee->type->elements.find(port_name);
          if( searchit != assignee->type->elements.end() ) {
            auto it = searchit->second;
            if( !type_compatible(*(it->type), *(assignee_port->type)) ) {
              std::stringstream strm;
              strm << i->location()
                << ": name match for port '" << port_name << "'"
                << " but no type match (expected: "
                << *(it->type)
                << ", got: "
                << *(assignee_port->type)
                << ")";
              throw std::runtime_error(strm.str());
            }

            if( matched_ports.count(assignee_port->name) > 0 ) {
              std::stringstream strm;
              strm << i->location()
                << ": port '" << assignee_port->name << "' already matched";
              throw std::runtime_error(strm.str());
            }

            std::shared_ptr<Port_assignment<Impl>> port_assign(new Port_assignment<Impl>);
            port_assign->port = it;
            // XXX assign object to element of composite type socket
            inst->connection.push_back(port_assign);
            matched_ports.insert(assignee_port->name);
          }
        }
      } else
        throw std::runtime_error("connection items should be either a list or a single identifier");
    }
    m_mod.instantiations[inst->name] = inst;

    auto obj = std::make_shared<Object<Impl>>();
    obj->name = inst->name;
    obj->type = inst->module->socket;

    m_mod.objects[obj->name] = obj;

    return inst;
  }
Exemple #29
0
static void
load_usual_group(const xmlNode *group, form_element_t *parent)
{
    const xmlNode *p = find_by_path(group, "Properties/Group")->children;

    int grouping = xstrcmp(p->content, "Horizontal") == 0
            ? GROUPING_HORIZONTAL
            : GROUPING_VERTICAL
    ;
    bool show_title = true;
    p = find_by_path(group, "Properties/ShowTitle");
    if (xstrcmp(children_content(p), "false") == 0)
        show_title = false;
    const xmlChar *title = entry_title_ex(group, false);

    int repr = REPRESENTATION_NONE;

    p = find_by_path(group, "Properties/Representation");
    const xmlChar *s = children_content(p);
    if (xstrcmp(s, "StrongSeparation") == 0)
        repr = REPRESENTATION_STRONG;

    form_element_t G;

    G.widget = grouping == GROUPING_HORIZONTAL
        ? gtk_hbox_new(false, repr == REPRESENTATION_STRONG ? 2 : 0)
        : gtk_vbox_new(false, repr == REPRESENTATION_STRONG ? 2 : 0)
    ;
    G.box = true;

    p = find_by_path(group, "ContainedItems");
    if (p) {

        int count_table;
        const xmlNode *cur_node = p->children;

        while (cur_node) {

            count_table = 0;

            if (grouping == GROUPING_VERTICAL) {
                const xmlNode *n = cur_node;
                while (n) {
                    if (is_oftype(n, "Text") || is_oftype(n, "Input")) {
                        ++count_table;
                        n = n->next;

                        while (n && n->type != XML_ELEMENT_NODE)
                            n = n->next;

                        if (!n)
                            break;
                    } else
                        break;
                }
            }

            if ((count_table > 1) && (grouping == GROUPING_VERTICAL)) {

                form_element_t T;
                T.widget = gtk_table_new(count_table, 2, false);
                T.table_index = 0;

                container_add(&G, T.widget);

                while (count_table--) {
                    if (is_oftype(cur_node, "Text") || is_oftype(cur_node, "Input")) {
                        load_text_entry(cur_node, &T, true);
                        ++T.table_index;
                    }
                    cur_node = cur_node->next;
                    while (cur_node && cur_node->type != XML_ELEMENT_NODE)
                        cur_node = cur_node->next;
                }
            }
            else {
                load_form_element(cur_node, &G);
                cur_node = cur_node->next;
            }
        }

    }

    if (repr == REPRESENTATION_STRONG) {
        GtkWidget *widget = gtk_frame_new("");

        if (show_title)
            gtk_frame_set_label(GTK_FRAME(widget), GTK_CHAR(title));

        gtk_container_add(GTK_CONTAINER(widget), G.widget);
        container_add(parent, widget);
    } else
        container_add(parent, G.widget);
}
Exemple #30
0
static void
load_text_entry(const xmlNode *text, form_element_t *parent, bool in_table)
{
    bool is_edit = true;
    const xmlNode *p;

    p = find_by_path(text, "Properties/Type");
    if (p)
        if (xstrcmp(children_content(p), "LabelField") == 0)
            is_edit = false;

    const xmlChar *label = entry_title_ex(text, is_edit);
    p = find_by_path(text, "Properties/TitleLocation");

    int title_loc = TITLE_LOCATION_LEFT;

    {
        const xmlChar *xc_title_loc = children_content(p);
        if (xc_title_loc) {
            if (xstrcmp(xc_title_loc, "None") == 0)
                title_loc = TITLE_LOCATION_NONE;
            if (xstrcmp(xc_title_loc, "Right") == 0)
                title_loc = TITLE_LOCATION_RIGHT;
        }
    }

    form_element_t E;
    E.box = false;

    if (label && title_loc != TITLE_LOCATION_NONE) {
        E.widget = gtk_hbox_new(false, 0);

        GtkWidget *w_label = gtk_label_new(GTK_CHAR(label));
        GtkWidget *w_edit = is_edit
            ? gtk_entry_new()
            : gtk_label_new("...")
        ;

        p = find_by_path(text, "Properties/HeaderHorizontalAlign");
        if (p)
            justify_element(w_label, p);

        if (!is_edit) {
            p = find_by_path(text, "Properties/HorizontalAlign");
            if (p)
                justify_element(w_edit, p);
        }

        if (in_table) {
            gtk_table_attach(GTK_TABLE(parent->widget),
                    w_label,
                    0, 1, parent->table_index + 1, parent->table_index + 2,
                    GTK_FILL, 0,
                    0, 0
            );
            gtk_table_attach(GTK_TABLE(parent->widget),
                    w_edit,
                    1, 2, parent->table_index + 1, parent->table_index + 2,
                    GTK_EXPAND | GTK_FILL, 0,
                    0, 0
            );
        } else {
            if (title_loc == TITLE_LOCATION_LEFT)
                gtk_box_pack_start(GTK_BOX(E.widget), w_label, false, false, 0);

            gtk_box_pack_start(GTK_BOX(E.widget), w_edit, true, true, 0);

            if (title_loc == TITLE_LOCATION_RIGHT)
                gtk_box_pack_start(GTK_BOX(E.widget), w_label, false, false, 0);

            container_add(parent, E.widget);
        }

    } else {
        if (is_edit)
            E.widget = gtk_entry_new();
        else {
            E.widget = gtk_label_new(GTK_CHAR(label));

            p = find_by_path(text, "Properties/HorizontalAlign");
            if (p)
                justify_element(E.widget, p);
        }

        if (in_table) {
            gtk_table_attach(GTK_TABLE(parent->widget),
                    E.widget,
                    1, 2, parent->table_index + 1, parent->table_index + 2,
                    GTK_EXPAND | GTK_FILL, 0,
                    0, 0
            );
        } else {
            container_add(parent, E.widget);
        }
    }
}