Você não está autenticado.
O fórum foi atualizado e está usando dois níveis de "autenticação" no registro de novos usuários para evitar o cadastro de bots, por favor, qualquer problema entrar em contato pelo e-mail forum@archlinux-br.org.
Por favor, leia as regras do fórum antes de usá-lo.
Páginas: 1
Pessoal,
Preciso de ajuda pra colocar um filtro de extenção de arquivos no GTK.
Na verdade preciso editar o fonte de um programa.
Quem trabalha com arquvios multimedia sabe que nem sempre temos somente arquivos de audio ou video nos diretórios.
Alguns programas criam arquivos de analises com o mesmo nome da midia e no mesmo diretório, com extenção diferente que geralmente servem como referencia pro programa que editou abriu ou criou.
Dai o problema é que meu tocador de audio preferido o Audacious, ele não filtra extenção dos arquivos. Dai quando vou abrir todos os arquivos (que geralmente não são poucos pra selecionar 1 a 1) ele acaba carregando esses "arquivos de analises" na playlist e todas as outras tranqueiras que tiver no diretório.
Isso encomoda um pouco porque os arquivos que não são de audio acabam causando erro e até travando o programa durante a execução.
Percebi que o responsável pela janela de seleção de arquivos é o ui_fileopener.c
/* Audacious - Cross-platform multimedia player
* Copyright (C) 2005-2007 Audacious development team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; under version 3 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses>.
*
* The Audacious team does not consider modular code linking to
* Audacious or using our public API to be a derived work.
*/
#include <gtk/gtk.h>
#include <audacious/audconfig.h>
#include <audacious/i18n.h>
#include <audacious/drct.h>
#include "config.h"
#include "libaudgui.h"
#include "libaudgui-gtk.h"
static void filebrowser_add_files (GtkFileChooser * browser, GSList * files,
gboolean play)
{
GSList * node;
GList * list = NULL;
for (node = files; node != NULL; node = node->next)
list = g_list_prepend (list, node->data);
list = g_list_reverse (list);
if (play)
aud_drct_pl_open_list (list);
else
aud_drct_pl_add_list (list, -1);
g_list_free (list);
g_free (aud_cfg->filesel_path);
aud_cfg->filesel_path = gtk_file_chooser_get_current_folder (browser);
}
static void
action_button_cb(GtkWidget *widget, gpointer data)
{
GtkWidget *window = g_object_get_data(data, "window");
GtkWidget *chooser = g_object_get_data(data, "chooser");
GtkWidget *toggle = g_object_get_data(data, "toggle-button");
GSList *files;
aud_cfg->close_dialog_open =
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle));
files = gtk_file_chooser_get_uris ((GtkFileChooser *) chooser);
filebrowser_add_files ((GtkFileChooser *) chooser, files, GPOINTER_TO_INT
(g_object_get_data (data, "play-button")));
g_slist_foreach(files, (GFunc) g_free, NULL);
g_slist_free(files);
if (aud_cfg->close_dialog_open)
gtk_widget_destroy(window);
}
static void
close_button_cb(GtkWidget *widget, gpointer data)
{
gtk_widget_destroy(GTK_WIDGET(data));
}
static void
run_filebrowser_gtk2style(gboolean play_button, gboolean show)
{
static GtkWidget *window = NULL;
GtkWidget *vbox, *hbox, *bbox;
GtkWidget *chooser;
GtkWidget *action_button, *close_button;
GtkWidget *toggle;
gchar *window_title, *toggle_text;
gpointer action_stock, storage;
if (!show) {
if (window){
gtk_widget_hide(window);
return;
}
else
return;
}
else {
if (window) {
gtk_window_present(GTK_WINDOW(window)); /* raise filebrowser */
return;
}
}
window_title = play_button ? _("Open Files") : _("Add Files");
toggle_text = play_button ?
_("Close dialog on Open") : _("Close dialog on Add");
action_stock = play_button ? GTK_STOCK_OPEN : GTK_STOCK_ADD;
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_type_hint (GTK_WINDOW (window), GDK_WINDOW_TYPE_HINT_DIALOG);
gtk_window_set_title(GTK_WINDOW(window), window_title);
gtk_window_set_default_size(GTK_WINDOW(window), 700, 450);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_container_set_border_width(GTK_CONTAINER(window), 10);
vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(window), vbox);
chooser = gtk_file_chooser_widget_new(GTK_FILE_CHOOSER_ACTION_OPEN);
gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(chooser), TRUE);
if (aud_cfg->filesel_path)
gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(chooser),
aud_cfg->filesel_path);
gtk_box_pack_start(GTK_BOX(vbox), chooser, TRUE, TRUE, 3);
hbox = gtk_hbox_new(TRUE, 0);
gtk_box_pack_end(GTK_BOX(vbox), hbox, FALSE, FALSE, 3);
toggle = gtk_check_button_new_with_label(toggle_text);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(toggle),
aud_cfg->close_dialog_open ? TRUE : FALSE);
gtk_box_pack_start(GTK_BOX(hbox), toggle, TRUE, TRUE, 3);
bbox = gtk_hbutton_box_new();
gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
gtk_box_set_spacing(GTK_BOX(bbox), 6);
gtk_box_pack_end(GTK_BOX(hbox), bbox, TRUE, TRUE, 3);
close_button = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
action_button = gtk_button_new_from_stock(action_stock);
gtk_container_add(GTK_CONTAINER(bbox), close_button);
gtk_container_add(GTK_CONTAINER(bbox), action_button);
/* this storage object holds several other objects which are used in the
* callback functions
*/
storage = g_object_new(G_TYPE_OBJECT, NULL);
g_object_set_data(storage, "window", window);
g_object_set_data(storage, "chooser", chooser);
g_object_set_data(storage, "toggle-button", toggle);
g_object_set_data(storage, "play-button", GINT_TO_POINTER(play_button));
g_signal_connect(chooser, "file-activated",
G_CALLBACK(action_button_cb), storage);
g_signal_connect(action_button, "clicked",
G_CALLBACK(action_button_cb), storage);
g_signal_connect(close_button, "clicked",
G_CALLBACK(close_button_cb), window);
g_signal_connect(window, "destroy",
G_CALLBACK(gtk_widget_destroyed), &window);
audgui_destroy_on_escape (window);
gtk_widget_show_all (window);
}
/*
* run_filebrowser(gboolean play_button)
*
* Inputs:
* - gboolean play_button
* TRUE - open files
* FALSE - add files
*
* Outputs:
* - none
*/
void
audgui_run_filebrowser(gboolean play_button)
{
run_filebrowser_gtk2style(play_button, TRUE);
}
void
audgui_hide_filebrowser(void)
{
run_filebrowser_gtk2style(FALSE, FALSE);
}Eu ja tentei incluir os filtros observado alguns exemplos na internet e até mesmo a documentação do GTK sobre FileChooser, neste link http://library.gnome.org/devel/gtk/unst … get-filter
Mas como não tenho noção nenhuma de C++ não obtive sucesso.
Se puderem me ajudar, fico grato!
Obrigado!
Última edição por cellexpert (27/11/2010 15:52:46)
Offline
Cacete, ainda não resolveram isso!
Já faz tempo, mas pra quem quiser ficaria mais ou menos assim:
media_types = ('mp3', 'mp4', 'ogg', 'avi', 'wav', 'wma', 'wmv', .... <seria uma lista realmente grande> ')
mediafilter = gtk.FileFilter()
for media_type in media_types:
mediafilter.add_pattern('*.' + media_type)
mediafilter.set_name(_("Arquivos Suportados"))
chooser.add_filter(mediafilter)
allfilter = gtk.FileFilter()
allfilter.add_pattern("*")
allfilter.set_name(_("Todos os Arquivos"))
chooser.add_filter(allfilter)Também poderia setar os patterns assim:
filter.add_pattern("*.mp3")
filter.add_pattern("*.ogg")
........Faz muito tempo que não mexo com c++ , e a quantidade de extensões de mídia suportadas pelo audacious é grande, chega ser até deselegante usar esse método de filtragem.
Se me der coragem depois eu penso em algo e envio pro git.
Talvez nem veja essa mensagem, mas pra quem aparecer por aqui, boa sorte.
Última edição por Mrk3004 (26/04/2012 03:37:53)
É um processo lento modificar princípios, e você nunca saberá que eles mudaram até que algo que parecia ser certo não pareça mais.
Offline
Páginas: 1