using System; using System.IO; using Gtk; using Glade; using System.Xml; using System.Xml.XPath; using System.Collections.Generic; using System.Collections; namespace AmicEditor { // Importació de la interfície per a l'audio per DBUS [NDesk.DBus.Interface("net.Lliurex.Media.AudioServer")] public interface IAudioServer { int LoadMedia(string filename); void Play(int id); void Stop(int id); } public class AmicEditor { /* * Classe Principal de l'aplicació * */ // Variables per a la reproducció d'àudio... int id_audio=-1; IAudioServer server; // Atributs per comunicar-nos amb el botó d'afegir categories: public static bool CreateNewCat {get;set;} public static string CreatedCathegoryName {get;set;} public static string CreatedCathegoryLang {get;set;} public static Gdk.Color CreatedCathegoryColor {get;set;} public static Gdk.Color CreatedCathegoryFontColor {get;set;} public static string CreatedCathegoryFont {get;set;} // Per comunicar-nos amb el botó d'afegir temes public static bool CreateNewTheme {get;set;} public static string CreatedThemeName {get;set;} public static string CreatedThemeDesc {get;set;} // I per comunicar-se amb els diàlegs de selecció de fitxers public static string SelectedImageFile {get;set;} public static string SelectedSoundFile {get;set;} /*// Definició de directoris string dir_resources=""; string dir_img=""; string dir_img_custom=""; string dir_audio=""; string dir_audio_custom=""; string dir_xml=""; string dir_gallery=""; string dir_themes=""; string dir_rsrc=""; string dir_default=""; string link_custom_image=""; string link_custom_audio=""; string link_default_image=""; string link_default_audio=""; */ // Atributs de la interfície: TreeIter iterSelected; [Widget] Window WinGallery; // Widget de l'aplicació principal // Widgets per gestionar categories [Widget] Button BtAddCathegory; [Widget] Button BtRemoveCathegory; // Widgets per als botons per a la gestió de pictogrames [Widget] Button BtNew; [Widget] Button BtDel; //[Widget] Button BtImport; [Widget] Button BtCopy; [Widget] Button BtCut; [Widget] Button BtPaste; // [Widget] EventBox eventboxPict; // [Widget] MenuBar menubar1; not used // Opcions de visualització i temes [Widget] ComboBox ComboBoxTheme; // Selecciona el tema a visualitzar [Widget] Button BtNewTheme; // Crea un tema nou // Botons sobre el pictograma actual [Widget] Button BtRestore; // Restaura els valors inicials [Widget] Button BtSave; // Guarda els canvis //Opcins sobre el pictograma actual [Widget] Entry InputTextName; // Nom del pictograma [Widget] ComboBox ComboBoxClass; // Classe del pict // Opcions del text [Widget] Entry InputTextCaption; // Text a mostrar [Widget] ComboBox ComboBoxLang; // Selector d'idioma [Widget] FontButton btnFont; // Botó de selecció de la font per al caption [Widget] ColorButton BtnFontColor; // Botó per canviar el color de la lletra al Caption //[Widget] RadioButton RBTop; //[Widget] RadioButton RBBottom; RadioButton RBTop; RadioButton RBBottom; [Widget] HBox BoxRBTop; [Widget] HBox BoxRBBottom; [Widget] ColorButton BtnBackground; // Botó per canviar el fons del pictograma //Sobre l'aspecte de la imatge [Widget] ComboBox InputComboTheme; // Per seleccionar el tema del pictograma //[Widget] FileChooserButton BtSelectImage; // Per triar la imatge [Widget] Button BtImgSel; // Per triar imatge 2!!!!!!!!!!! [Widget] Button BtSndSel; // Per triar el sò //[Widget] Image PictImageToShow; // Imatge que es mostrarà Image PictImageToShow; //Opcions de les accions [Widget] Entry InputTextToSpeech; // Per introduir el text per deletrejar // [Widget] FileChooserButton FileChooseSound; // Arxiu de sò //Imatges [Widget] Button BtSound; // Reprodueix el sò [Widget] Button BtSpeech; // Llegeix el text // Previsualització [Widget] DrawingArea Preview; // Menú [Widget] MenuItem MenuItemImportPla; // Opció de menú per importar de plaphoons [Widget] MenuItem MenuItemNewCathehory; [Widget] MenuItem MenuItemImportGallery; [Widget] MenuItem MenuItemExportGallery; [Widget] MenuItem MenuItemExportOO; [Widget] MenuItem menuExportSVG; [Widget] MenuItem MenuPreferences; [Widget] MenuItem itemAbout; // [Widget] VBox BoxBtImg; [Widget] TreeView treeCategoryView; // On es mostren les diferents categories // Per gestionar la imatge del botó "Color Per Defecte" Gtk.Image MiImage; [Widget] Gtk.Button BtImgDefault; // Widgets per a la gestió de la finestar d'icones [Widget] HBox BoxIconView; // Caixa on estarà l'IconView ScrolledWindow sw; // Constants per a l'IconView const int COL_DISPLAY_NAME = 1; const int COL_PIXBUF = 2; // VBox vboxIcons=null; NOT USED ListStore IconStore=null; IconView iconView=null; // Galeries, temes i categories... Gallery MyGallery; Themes MyThemes; Cathegory PictogramsActual; // Pictogrames Pictogram CurrentPic; // Pictogrma actual... Pictogram SelectedPic; // Pictogarma actual per fer operacions // Per fer les operacions de copy i paste List ListToCopy; //Pictogram Copied; // Pictograma Per fer les còpies int CopyOrCut=0; // 0 No selection; 1 Copy; 2 Cut string CatFromCut=""; string CatActual=""; // NOT USED Gdk.Color CatColor=new Gdk.Color(0,0,0); // Per dibuixar o no les columnes a les categories bool first_execution=true; public AmicEditor (string[] args){ /* * Constructor de l'aplicació principal: Inicialitza la interfície, els elements i llença el bucle principal. * * */ Gtk.Application.Init (); Mono.Unix.Catalog.Init("lliurex-amic-editor","/usr/share/locale/"); // Per establir l'idioma //string test=Mono.Unix.Catalog.GetString("New"); //if (test=="Nou") Preferences.lang_code="qcv_ES"; //else if (test=="Nuevo") Preferences.lang_code="es_ES"; //else Preferences.lang_code="en_GB"; // INICIALITZACIÓ DE L'AUDIO NDesk.DBus.ObjectPath path = new NDesk.DBus.ObjectPath("/net/Lliurex/Media/AudioServer"); server = NDesk.DBus.Bus.Session.GetObject("net.Lliurex.Media.AudioServer",path); //Llegim la configuració de l'arxiu /etc/amic.conf Preferences.LoadPreferences(); //LoadConf(); // I carreguem les galeries i els temes MyGallery = new Gallery(); // Li passem els directoris MyThemes = new Themes(); // Pictograma actual //CurrentPic=new Pictogram(); //Glade.XML gxml = new Glade.XML(null, dir_rsrc+"/GalleryPicts.glade", "WinGallery", null); //Glade.XML gxml = new Glade.XML(null, "GalleryPicts.glade", "WinGallery", null); Glade.XML gxml = new Glade.XML(null, "GalleryPicts.glade", "WinGallery", null); gxml.Autoconnect (this); // Directoris per defecte d'audio i imatges //FileChooseSound.SetCurrentFolder(dir_audio); //BtSndSel.Label= //BtSelectImage.SetCurrentFolder(dir_img); // Afegim les imatges als botons... AddImagesToButtons(); // Inicialitzem la imatge a mostrar PictImageToShow=new Image(); // Inicialitzem la llista de pictogrames per copiar ListToCopy=new List(); // Inicialitzem els radio buttons RBTop = new RadioButton (null, "Top"); BoxRBTop.PackStart(RBTop, true, true, 0); RBTop.Show(); RBBottom = new RadioButton(RBTop, "Bottom"); RBBottom.Active = true; BoxRBBottom.PackStart(RBBottom, true, true, 0); RBBottom.Show(); // Preparem el botó per carregar imatges BtImgSel.Image=new Image(Stock.File, IconSize.Button); BtImgSel.ImagePosition=PositionType.Right; // Associem els events AddEventListeners(); // Inicialitzem el combo dels temes InitComboThemes(); // Inicialitzem els idiomes InitComboLang(); // Omplim els elements de la interfície amb les dades de la galeria AddCathegoriesToView(); // Inicialització de l'IconView InitIconView(); // TO DELETE***************************** //SaveFileWindow filedlg=new SaveFileWindow(this.BtImgSel.Label); //SaveSoundWindow filedlg=new SaveSoundWindow(this.BtImgSel.Label); // filedlg.Show(); //***************************************** // Comprovem si és la primera execució //FirstRun(); // No s'usa // Mostrem la finestra de l'aplicació i l'executem WinGallery.ShowAll(); //w.Destroy(); Gtk.Application.Run(); } /* OBSOLETE FUNCTION. NOT USED. * * public void FirstRun(){ string HomeDir=Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); string linia; bool GalleriesBookmarksExists=false; if (File.Exists(HomeDir+"/.gtk-bookmarks")){ FileStream fs = new FileStream(HomeDir+"/.gtk-bookmarks", FileMode.Open, FileAccess.Read); StreamReader sr=new StreamReader(fs); while((linia=sr.ReadLine())!=null){ Console.WriteLine(linia); if (linia.Contains("file:///var/lib/lliurex-amic/ImageGallery/Default/")){ GalleriesBookmarksExists=true; break; } } fs.Close(); sr.Close(); } if(!GalleriesBookmarksExists){ string DefaultImageGallery=Mono.Unix.Catalog.GetString("Default Image Gallery"); string CustomImageGallery=Mono.Unix.Catalog.GetString("Custom Image Gallery"); string DefaultAudioGallery=Mono.Unix.Catalog.GetString("Default Audio Gallery"); string CustomAudioGallery=Mono.Unix.Catalog.GetString("Custom Audio Gallery"); FileStream fs = new FileStream(HomeDir+"/.gtk-bookmarks", FileMode.Append, FileAccess.Write); StreamWriter sw =new StreamWriter(fs); sw.WriteLine("file:///var/lib/lliurex-amic/ImageGallery/Default/ "+DefaultImageGallery); sw.WriteLine("file:///var/lib/lliurex-amic/ImageGallery/Custom/ "+CustomImageGallery); sw.WriteLine("file:///var/lib/lliurex-amic/AudioGallery/Default/ "+DefaultAudioGallery); sw.WriteLine("file:///var/lib/lliurex-amic/AudioGallery/Custom/ "+CustomAudioGallery); sw.Close(); fs.Close(); Gtk.MessageDialog msg=new Gtk.MessageDialog(null, Gtk.DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, "LliureX Amic", ""); msg.SecondaryUseMarkup=true; msg.SecondaryText=Mono.Unix.Catalog.GetString("It's firs time that you execute LliureX Amic. \n") + Mono.Unix.Catalog.GetString("LliureX Amic has created for you these bookmarks linking \n") + Mono.Unix.Catalog.GetString("Audio and Image Galleries:\n\n") + "- "+DefaultImageGallery+", "+Mono.Unix.Catalog.GetString("to locate default images.\n") + "- "+CustomImageGallery+", "+Mono.Unix.Catalog.GetString("to locate your own images \n") + Mono.Unix.Catalog.GetString(" for using with LliureX Amic.\n") + "- "+DefaultAudioGallery+", "+Mono.Unix.Catalog.GetString("to locate default sounds.\n") + "- "+CustomAudioGallery+", "+Mono.Unix.Catalog.GetString("to locate your own audio\n") + Mono.Unix.Catalog.GetString(" and recordings."); msg.Run(); msg.Destroy(); } } */ public void AddImageToButton(string image, string stock, Button Boto, int tamX, int tamY){ // Utilitat per assignar una imatge a un botó. if (System.IO.File.Exists(Preferences.dir_rsrc+"/"+image)) { MiImage = new Gtk.Image(Preferences.dir_rsrc+"/"+image); if (tamX!=0) MiImage.Pixbuf=MiImage.Pixbuf.ScaleSimple(tamX, tamY, Gdk.InterpType.Bilinear); Boto.Image=MiImage; } else { MiImage = new Image(stock, IconSize.Button); Boto.Image=MiImage; } } public void AddImagesToButtons(){ // Afig les imatges corresponents als botons de la interfície AddImageToButton("Default.png", Stock.Remove, BtImgDefault, 0,0); AddImageToButton("nou.png", Stock.Add, BtNew, 45, 45); AddImageToButton("del.png", Stock.Remove, BtDel, 45, 45); AddImageToButton("copy.png", Stock.Copy, BtCopy, 45, 45); AddImageToButton("cut.png", Stock.Cut, BtCut, 45, 45); AddImageToButton("paste.png", Stock.Paste, BtPaste, 45, 45); AddImageToButton("newcat.png", Stock.Add, BtAddCathegory, 45, 45); AddImageToButton("delcat.png", Stock.Remove, BtRemoveCathegory, 45, 45); AddImageToButton("newtheme.png", Stock.New, BtNewTheme, 45, 45); AddImageToButton("UndoChanges.png", Stock.Undo, BtRestore, 45, 45); AddImageToButton("SaveChanges.png", Stock.Save, BtSave, 45, 45); //AddImageToButton("AddToGrid.png", Stock.Add, BtImport, 45, 45); AddImageToButton("speech.png", Stock.MediaPlay, BtSpeech, 16, 16); AddImageToButton("play.png", Stock.MediaPlay, BtSound, 16, 16); // Afegim la imatge al botó Default /* if (System.IO.File.Exists(Preferences.dir_rsrc+"/Default.png")) { MiImage = new Gtk.Image(Preferences.dir_rsrc+"/Default.png"); BtImgDefault.Image=MiImage; } else { MiImage = new Image(Stock.Remove, IconSize.Button); BtImgDefault.Image=MiImage; } // Imatge per al botó Add Pictogram if (System.IO.File.Exists(Preferences.dir_rsrc+"/add1.png")) { MiImage = new Gtk.Image(Preferences.dir_rsrc+"/add1.png"); MiImage.Pixbuf=MiImage.Pixbuf.ScaleSimple(30, 30, Gdk.InterpType.Bilinear); BtNew.Image=MiImage; //BtImgDefault.Image=MiImage; } else { MiImage = new Image(Stock.Add, IconSize.Button); BtNew.Image=MiImage; }*/ } public static void Main (string[] args) { /* * Funció Principal: Crea una instància de la classe AmicEditor * */ new AmicEditor(args); } public void InitComboThemes(){ /* * Inicialitza els ComboBoxs on apareixen els temes, a partir dels temes existents * Crea l'objecte MyThemes, de la classe Themes, que és una llista de Theme. * * */ ListStore store = new ListStore(typeof (string), typeof (string), typeof(string)); this.ComboBoxTheme.Clear(); // Combo per triar el tema de visualització this.InputComboTheme.Clear(); // Combo per triar el tema del pictograma actual Gtk.CellRendererText cell=new Gtk.CellRendererText(); this.ComboBoxTheme.PackStart(cell, true); this.InputComboTheme.PackStart(cell, true); this.ComboBoxTheme.AddAttribute(cell, "text", 0); this.InputComboTheme.AddAttribute(cell, "text", 0); this.ComboBoxTheme.Model = store; this.InputComboTheme.Model = store; //ComboBoxTheme.TextColumn=0; //InputComboTheme.TextColumn=0; foreach (Theme tem in MyThemes.themes){ //Console.WriteLine("Nom del tema..."+tem.name); //store.AppendValues(tem.name, tem.description, tem.folder); store.AppendValues(tem.name, tem.description); } TreeIter MyIter; ComboBoxTheme.Model.GetIterFirst (out MyIter); InputComboTheme.Model.GetIterFirst (out MyIter); ComboBoxTheme.SetActiveIter(MyIter); InputComboTheme.SetActiveIter(MyIter); } public void InitComboLang(){ /* * Inicialitza el ComboBox dels idiomes * * */ ListStore store = new ListStore(typeof (string), typeof (string), typeof(string)); this.ComboBoxLang.Clear(); // Combo per triar el tema de visualització Gtk.CellRendererText cell=new Gtk.CellRendererText(); this.ComboBoxLang.PackStart(cell, true); this.ComboBoxLang.AddAttribute(cell, "text", 0); this.ComboBoxLang.Model = store; //this.ComboBoxLang.TextColumn=0; // ComboBoxLang.TextColumn=0; store.AppendValues( Mono.Unix.Catalog.GetString("Valencian"), "qcv_ES"); store.AppendValues( Mono.Unix.Catalog.GetString("Spanish"), "es_ES"); store.AppendValues( Mono.Unix.Catalog.GetString("English"), "en_GB"); //Cal buscar l'idioma en les preferències //TreeIter MyIter; //ComboBoxLang.Model.GetIterFirst (out MyIter); //ComboBoxLang.SetActiveIter(MyIter); TreeIter Myiter; ComboBoxLang.Model.GetIterFirst(out Myiter); do { GLib.Value thisRow = new GLib.Value (); ComboBoxLang.Model.GetValue (Myiter, 1, ref thisRow); Console.WriteLine("-----------Lang: "+thisRow.Val.ToString()); if ((thisRow.Val as string).Equals(Preferences.lang_code)) { Console.WriteLine("Lang: "+Preferences.lang_code); ComboBoxLang.SetActiveIter (Myiter); break; } } while (ComboBoxLang.Model.IterNext (ref Myiter)); } /*protected void LoadConf(){ /* * Llegeix el contingut de l'arxiu /etc/amic.conf * I inicialitza les variables de l'aplicació i els directoris * * / StreamReader fd=File.OpenText("/etc/lliurex-amic/amic.conf"); string linia; while((linia=fd.ReadLine())!=null){ if (linia.IndexOf('=')!=-1){ string [] var_valor = linia.Split(new Char [] {'='}); Console.WriteLine(var_valor[0]+" val "+var_valor[1]); switch (var_valor[0]){ case "dir_resources": dir_resources=var_valor[1]; break; case "dir_img": dir_img=var_valor[1]; break; case "dir_audio": dir_audio=var_valor[1]; break; case "dir_img_custom": dir_img_custom=var_valor[1]; break; case "dir_audio_custom": dir_audio_custom=var_valor[1]; break; case "dir_xml": dir_xml=var_valor[1]; break; case "dir_gallery": dir_gallery=var_valor[1]; break; case "dir_themes": dir_themes=var_valor[1]; break; case "dir_rsrc": dir_rsrc=var_valor[1]; break; case "dir_default": dir_default=var_valor[1]; break; case "link_custom_image_gallery": link_custom_image=var_valor[1]; break; case "link_default_image_gallery": link_default_image=var_valor[1]; break; case "link_default_audio_gallery": link_default_audio=var_valor[1]; break; case "link_custom_audio_gallery": link_custom_audio=var_valor[1]; break; } // Switch } //if } // While } // end LoadConf */ public void InitIconView(){ /* * Inicialitza la vista de les icones amb les propietats per defecte * S'usa també per al refresc de la vista * * */ sw=new ScrolledWindow(); // Inici de l'scroll window sw.ShadowType = ShadowType.EtchedIn; // Propietats sw.SetPolicy(PolicyType.Automatic, PolicyType.Automatic); sw.SetSizeRequest(200,200); BoxIconView.PackStart(sw, true, true, 0); // Propietats de l'HBox amb les icones //BoxIconView.SetSizeRequest(300,200); } public void AddCathegoriesToView(){ /* * Afig una categoria a l'IconView de categories * * */ List LlistaCat=new List(); LlistaCat=MyGallery.getCathegories(); // Creem les columnes Gtk.TreeViewColumn ColNom=new Gtk.TreeViewColumn(); Gtk.TreeViewColumn ColNum=new Gtk.TreeViewColumn(); Gtk.TreeViewColumn ColPath=new Gtk.TreeViewColumn(); ColNom.Title="Cathegory name"; ColNum.Title="Pictograms"; //ColPath.Title="Path"; // Aquesta columna no es mostrarà Gtk.CellRendererText categoria=new Gtk.CellRendererText(); Gtk.CellRendererText cat_num=new Gtk.CellRendererText(); Gtk.CellRendererText cat_path=new Gtk.CellRendererText(); ColNom.PackStart(categoria, true); ColNom.SortColumnId=0; ColNom.SortIndicator=true; ColNom.Clickable=true; ColNum.PackStart(cat_num, true); ColNum.SortColumnId=1; ColNum.SortIndicator=true; ColNom.Clickable=true; ColPath.PackStart(cat_path, true); // S'afigen les columnes a la vista if (first_execution){ treeCategoryView.AppendColumn(ColNom); treeCategoryView.AppendColumn(ColNum); first_execution=false; //treeCategoryView.AppendColumn(ColPath); // Diem la info a mostrar ColNom.AddAttribute(categoria, "text", 0); ColNum.AddAttribute(cat_num, "text", 1); ColPath.AddAttribute(cat_path, "text", 2); treeCategoryView.Selection.Changed += HandleTreeCategoryViewSelectionChanged; treeCategoryView.ButtonPressEvent += HandleTreeCategoryViewButtonPressEvent; } // Afegim la informació de les categories //Gtk.ListStore llista=new Gtk.ListStore(typeof(string), typeof(string),typeof(string)); Gtk.TreeStore llista=new Gtk.TreeStore(typeof(string), typeof(string),typeof(string)); for (int i=0;i0) // Si té algun element (sw=ScrolledView, la vista de les icones) { Widget old=sw.Children[0]; sw.Remove(old); } /* Carreguem els pictogrames d'on toca... */ IconStore.Clear(); Gdk.Pixbuf MiPixbuf; if(Cat!=null){ foreach(Pictogram pict in Cat.GetPictograms() ) { Console.WriteLine("pict..."+pict.pictname); if (pict.images.Count>0){ // Si el pictograma té imatges... bool has_no_images=true; // Patch: Per si creem un tema nou, no te info sobre la imatge... int index_pic=0; // Per treure el tema... int i; Console.WriteLine("PICTS: "+pict.images.Count); for(i=0;i0) { sel=iconView.SelectedItems[0]; //Console.WriteLine(sel); IconStore.GetIter(out iter, sel); //Console.WriteLine(IconStore.GetValue(iter,2).ToString()); nomPictActual=IconStore.GetValue(iter, 1).ToString(); catname=IconStore.GetValue(iter, 0).ToString(); } //if (CatName=="") CatActual=catname; // Categoria actual-> global Console.WriteLine("nomPictActual= "+nomPictActual+", Categoria="+catname); try{ // A partir del nom, obtenim la informació del pictograma if (nomPictActual!=""){ this.CurrentPic=this.PictogramsActual.GetPictogram(nomPictActual); // Una vegada el tenim en CurrentPic, actualitzem la informació de sota RefreshInfoPictogram(); // I refresquem la imatge seleccionada en el tema... RefreshImageTheme(); } } catch (Exception exc){ Console.WriteLine("Exception: "+exc); //return null; } // I activem els elements per manipular el pictograma if (iconView.SelectedItems.Length>0) { SetControlsPictogram(true); } else SetControlsPictogram(false); } public void RefreshInfoPictogram(){ // SelectedPic s'usa per no modificar l'objecte que representa el pictograma actual if (SelectedPic!=null) SelectedPic=null; this.SelectedPic=this.CurrentPic.Copy(); // Selectedpic és una còpia de CurrentPic /******** Omplim el formulari *********/ InputTextName.Text=this.SelectedPic.pictname ; // Nom del pictograma InputTextCaption.Text=this.SelectedPic.caption; // Text a mostrar InputTextToSpeech.Text=this.SelectedPic.actionSpeech ; // Per introduir el text per lletrejar Console.WriteLine("El SO VAL:" + SelectedPic.actionSound); Console.WriteLine("RUTA: " + Preferences.dir_audio); if (this.SelectedPic.actionSound!=""&&File.Exists(Preferences.dir_audio+"/"+this.SelectedPic.actionSound)){ Console.WriteLine("Exists: "+Preferences.dir_audio+"/"+this.SelectedPic.actionSound); //FileChooseSound.SetFilename(dir_audio+"/"+this.SelectedPic.actionSound); BtSndSel.Label=this.SelectedPic.actionSound; } else{ Console.WriteLine("Not Exists: "+Preferences.dir_audio+"/"+this.SelectedPic.actionSound); //FileChooseSound.SetCurrentFolder(dir_audio); BtSndSel.Label=""; } // Agafem les diferents categories i omplim el ComboBoxClass List LlistaCat=new List(); LlistaCat=MyGallery.getCathegories(); ListStore store = new ListStore(typeof (string)); this.ComboBoxClass.Clear(); Gtk.CellRendererText cell=new Gtk.CellRendererText(); this.ComboBoxClass.PackStart(cell, true); ComboBoxClass.AddAttribute(cell, "text", 0); this.ComboBoxClass.Model = store; //ComboBoxClass.TextColumn=0; for(int i=0;i>>>>>>>>>>>>>>>>"); //this.CurrentPic.actionSound=this.SelectedPic.actionSound; foreach(Theme th in MyThemes.getThemes()) { string imatge=SelectedPic.getImageFromTheme(th.name); //Console.WriteLine("Guarde la imatge: "+imatge+" en el tema: " + th.name); this.CurrentPic.setImageTheme(imatge, th.name); } Pango.FontDescription desc=Pango.FontDescription.FromString(btnFont.FontName); /*Console.WriteLine("Family: "+desc.Family); Console.WriteLine("Weight: "+desc.Weight); Console.WriteLine("Style: "+desc.Style); Console.WriteLine("Size: *"+(desc.Size/1000)+"*"); Console.WriteLine(" FONT: "+btnFont.FontName);*/ this.CurrentPic.fontface=desc.Family; this.CurrentPic.typeface=desc.Weight+" "+desc.Style; this.CurrentPic.fontsize=(desc.Size/1000).ToString(); this.CurrentPic.fontcolor=BtnFontColor.Color; this.CurrentPic.background=BtnBackground.Color; // RadioButtons if (RBTop.Active) // Está en bottom, cal canviar-lo this.CurrentPic.align="top"; else this.CurrentPic.align="bottom"; TreeIter iter; ComboBoxLang.GetActiveIter(out iter); GLib.Value thisRow = new GLib.Value(); ComboBoxLang.Model.GetValue (iter, 1, ref thisRow); this.CurrentPic.lang=thisRow.Val.ToString(); Console.WriteLine("GRAVEEEE: "+this.CurrentPic.lang); Console.WriteLine("Saving... "+CatActual+".xml"); PictogramsActual.Save(); if(apply_cat_change==true){ // Canviem la categoria Cathegory OldCat=MyGallery.GetPictogramsFrom(CatActual); Cathegory NewCat=MyGallery.GetPictogramsFrom(ComboBoxClass.ActiveText); Pictogram noupic=CurrentPic.Copy(); NewCat.AddPictogram(noupic); //NewCat.numpicts++; OldCat.Del(CurrentPic.pictname); //OldCat.numpicts--; Console.WriteLine("Saving... "+NewCat.cathegoryname+".xml"); NewCat.Save(); OldCat.Save(); } MyGallery = new Gallery(); string cat_tmp=PictogramsActual.cathegoryname; AddCathegoriesToView(); PictogramsActual=MyGallery.GetPictogramsFrom(cat_tmp); //PictogramsActual=MyGallery.GetPictogramsFrom(); AddPictogramsToView(PictogramsActual); } } } }// Del if } catch (Exception ex){ Console.WriteLine("Excepcio: "+ex); } } void HandleBtRestoreClicked (object sender, EventArgs e) {// TODO : PROVAR QUE AÇÒ VAJA QUAN FAÇA VISIBLES LES MODIFICACIONS if(CurrentPic!=null&&SelectedPic!=null){ // Una vegada el tenim en CurrentPic, actualitzem la informació de sota RefreshInfoPictogram(); // I refresquem la imatge seleccionada en el tema... RefreshImageTheme(); } } void HandleBtNewThemeClicked (object sender, EventArgs e) { /* * Obre un nou diàleg per crear una tematització nova * */ NewThemeDialog dlgnou=new NewThemeDialog(MyThemes); dlgnou.Show(); if (CreateNewTheme){ Theme TemNou=new Theme(CreatedThemeName, CreatedThemeDesc);// nom i categoria MyThemes.Add(TemNou); InitComboThemes(); CreateNewTheme=false; } //AddCathegoriesToView(); } void HandleBtPasteClicked (object sender, EventArgs e) { try{ /* if(CopyOrCut!=0){ foreach(Pictogram p in ListToCopy){ PastePicto(p); }*/ string pictname=""; if(CopyOrCut!=0){ //if (PictogramsActual!=null&&Copied!=null){ if (PictogramsActual!=null&&ListToCopy.Count>0){ foreach(Pictogram p in ListToCopy){ Pictogram nou=new Pictogram(); //nou=Copied.Copy(); nou=p.Copy(); pictname=nou.pictname; if (!PictogramsActual.ExistsPicWithName(p.pictname)) nou.pictname=p.pictname; else{ int i=0; while(PictogramsActual.ExistsPicWithName(p.pictname+i.ToString())) i++; nou.pictname=p.pictname+i.ToString(); } //PictogramsActual.numpicts++; PictogramsActual.AddPictogram(nou); PictogramsActual.Save(); // Guardem els canvis if (CopyOrCut==2) // S'ha fet un Cut!! { Cathegory ToDelete=MyGallery.GetPictogramsFrom(CatFromCut); ToDelete.Del(p.pictname); // // AddPictogramsToView(PictogramsActual); //ToDelete.numpicts--; // Cal guardar el pictograma anterior sense el pictograma retallat ToDelete.Save(); } pictname=nou.pictname; // Per seleccionar el nou pictograma } } CopyOrCut=0; // Ja hem fet les operacions... ListToCopy.Clear(); // Netegem la llista // InputComboTheme refresquem... string cat_tmp=PictogramsActual.cathegoryname; AddPictogramsToView(PictogramsActual); AddCathegoriesToView(); PictogramsActual=MyGallery.GetPictogramsFrom(cat_tmp); Gtk.TreeIter Myiter; Gtk.TreePath MyPath; iconView.Model.GetIterFirst(out Myiter); do { GLib.Value thisRow = new GLib.Value (); iconView.Model.GetValue (Myiter, 1, ref thisRow); //Console.WriteLine(thisRow.Val as string); if ((thisRow.Val as string).Equals(pictname)) { Console.WriteLine("El nom es..."+pictname); MyPath=iconView.Model.GetPath(Myiter); iconView.SelectPath(MyPath); break; } } while (iconView.Model.IterNext(ref Myiter)); } } catch (Exception exc){ Console.WriteLine("Exception: "+exc); } } void HandleBtCutClicked (object sender, EventArgs e) { try{ HandleBtCopyClicked(sender, e); CopyOrCut=2; // 2=cut CatFromCut=PictogramsActual.cathegoryname; // Agafem el nom de la categoria /* if (CurrentPic!=null) Copied=CurrentPic.Copy(); CopyOrCut=2; // 2=cut CatFromCut=PictogramsActual.cathegoryname; // Agafem el nom de la categoria //Console.WriteLine("Click on Button Cut");*/ } catch (Exception exc){ Console.WriteLine("Cut Exception: "+exc); } } void HandleBtCopyClicked (object sender, EventArgs e) { if(iconView!=null){ TreePath[] paths = iconView.SelectedItems; if (paths.Length > 0) { TreeIter iter; Pictogram p=new Pictogram(); foreach(TreePath t in paths){ iconView.Model.GetIter(out iter, t); p=PictogramsActual.GetPictogram((iconView.Model.GetValue(iter, 1)).ToString()); ListToCopy.Add(p); /*Console.WriteLine(iconView.Model.GetValue(iter, 0)); Console.WriteLine(iconView.Model.GetValue(iter, 1)); Console.WriteLine(iconView.Model.GetValue(iter, 2)); Console.WriteLine(iconView.Model.GetValue(iter, 3)); */ } //iconView //store.GetIter (out iter, paths[0]); //return store.GetValue (iter, 2); } //iconView.Model.GetIterFirst(out Myiter); //MyPath=iconView.Model.GetPath(Myiter); /* iconView.SelectPath(MyPath); Console.WriteLine(npicts); if (npicts>=0){ // Seleccionem el primer... /** / //PictogramsActual.numpicts--; AddCathegoriesToView(); PictogramsActual=MyGallery.GetPictogramsFrom(cat_tmp); /**** / } * }*/ //if (CurrentPic!=null) Copied=CurrentPic.Copy(); CopyOrCut=1; // 1=copy //Console.WriteLine("Click on Button Copy"); } } void HandleBtDelClicked (object sender, EventArgs e) { // Eliminem try{ //if(CurrentPic!=null&&SelectedPic!=null){ if(iconView!=null){ TreePath[] paths = iconView.SelectedItems; if (paths.Length > 0) { TreeIter iter; //Pictogram p=new Pictogram(); foreach(TreePath t in paths){ iconView.Model.GetIter(out iter, t); PictogramsActual.Del(PictogramsActual.GetPictogram((iconView.Model.GetValue(iter, 1)).ToString()).pictname); } PictogramsActual.Save(); //int npicts=PictogramsActual.numpicts; // Pictogrames que queden // Guardem la categoria per no pedre-la en AddCathegories... string cat_tmp=PictogramsActual.cathegoryname; AddCathegoriesToView(); PictogramsActual=MyGallery.GetPictogramsFrom(cat_tmp); AddPictogramsToView(PictogramsActual); /* //Console.WriteLine("PitName:---------"+CurrentPic.pictname); //Console.WriteLine("SelName:---------"+SelectedPic.pictname); if (PictogramsActual.numpicts>0) { PictogramsActual.Del(CurrentPic.pictname); PictogramsActual.Save(); int npicts=PictogramsActual.numpicts; // Pictogrames que queden // Guardem la categoria per no pedre-la en AddCathegories... string cat_tmp=PictogramsActual.cathegoryname; AddPictogramsToView(PictogramsActual); Gtk.TreeIter Myiter; Gtk.TreePath MyPath; if (npicts>=0){ // Seleccionem el primer... /** / //PictogramsActual.numpicts--; AddCathegoriesToView(); PictogramsActual=MyGallery.GetPictogramsFrom(cat_tmp); /**** / iconView.Model.GetIterFirst(out Myiter); MyPath=iconView.Model.GetPath(Myiter); iconView.SelectPath(MyPath); Console.WriteLine(npicts); } */ } } }catch(Exception exc){ Console.WriteLine("Excepcio: "+exc); } } void HandleBtNewClicked (object sender, EventArgs e) { if (PictogramsActual!=null){ Pictogram nou=new Pictogram(); if (!PictogramsActual.ExistsPicWithName("new")) nou.pictname="new"; else{ int i=0; while(PictogramsActual.ExistsPicWithName("new"+i.ToString())) i++; nou.pictname="new"+i.ToString(); } nou.background=PictogramsActual.BackgroundColor; nou.lang=PictogramsActual.DefaultLang; PictogramsActual.AddPictogram(nou); // Guardem la categoria per no pedre-la en AddCathegories... string cat_tmp=PictogramsActual.cathegoryname; AddPictogramsToView(PictogramsActual); AddCathegoriesToView(); PictogramsActual=MyGallery.GetPictogramsFrom(cat_tmp); // Per portar el focus al pictograma creat Gtk.TreeIter Myiter; Gtk.TreePath MyPath; iconView.Model.GetIterFirst(out Myiter); do { GLib.Value thisRow = new GLib.Value (); iconView.Model.GetValue (Myiter, 1, ref thisRow); if ((thisRow.Val as string).Equals(nou.pictname)) { Console.WriteLine("El nom es..."+nou.pictname); MyPath=iconView.Model.GetPath(Myiter); iconView.SelectPath(MyPath); iconView.SetCursor(MyPath, null, true); break; } } while (iconView.Model.IterNext(ref Myiter)); /* * * * if (PictogramsActual!=null&&Copied!=null){ Pictogram nou=new Pictogram(); nou=Copied.Copy(); pictname=nou.pictname; if (!PictogramsActual.ExistsPicWithName(Copied.pictname)) nou.pictname=Copied.pictname; else{ int i=0; while(PictogramsActual.ExistsPicWithName(Copied.pictname+i.ToString())) i++; nou.pictname=Copied.pictname+i.ToString(); } //PictogramsActual.numpicts++; PictogramsActual.AddPictogram(nou); PictogramsActual.Save(); // Guardem els canvis if (CopyOrCut==2) // S'ha fet un Cut!! { Cathegory ToDelete=MyGallery.GetPictogramsFrom(CatFromCut); ToDelete.Del(Copied.pictname); AddPictogramsToView(PictogramsActual); //ToDelete.numpicts--; // Cal guardar el pictograma anterior sense el pictograma retallat ToDelete.Save(); } pictname=nou.pictname; // Per seleccionar el nou pictograma } CopyOrCut=0; // InputComboTheme refresquem... string cat_tmp=PictogramsActual.cathegoryname; AddPictogramsToView(PictogramsActual); AddCathegoriesToView(); PictogramsActual=MyGallery.GetPictogramsFrom(cat_tmp); Gtk.TreeIter Myiter; Gtk.TreePath MyPath; iconView.Model.GetIterFirst(out Myiter); do { GLib.Value thisRow = new GLib.Value (); iconView.Model.GetValue (Myiter, 1, ref thisRow); //Console.WriteLine(thisRow.Val as string); if ((thisRow.Val as string).Equals(pictname)) { Console.WriteLine("El nom es..."+pictname); MyPath=iconView.Model.GetPath(Myiter); iconView.SelectPath(MyPath); break; } } while (iconView.Model.IterNext(ref Myiter)); } } * * * * * * * * * * * */ } //Console.WriteLine("Click on Button New"); } static void EventTancarFinestra(object obj, DeleteEventArgs args) { Gtk.Application.Quit(); } protected void AddEventListeners(){ // Associa tots els gestors d'events // ClickEventTreeHandler WinGallery.DeleteEvent +=new DeleteEventHandler(EventTancarFinestra); BtNew.Clicked += HandleBtNewClicked; // BtImport.Clicked += HandleBtImportClicked; BtDel.Clicked += HandleBtDelClicked; BtCopy.Clicked += HandleBtCopyClicked; BtCut.Clicked += HandleBtCutClicked; BtPaste.Clicked += HandleBtPasteClicked; BtAddCathegory.Clicked += HandleBtAddCathegoryClicked; BtRemoveCathegory.Clicked += HandleBtRemoveCathegoryClicked; ComboBoxTheme.Changed += HandleComboBoxThemeChanged; BtNewTheme.Clicked += HandleBtNewThemeClicked; BtRestore.Clicked += HandleBtRestoreClicked; BtSave.Clicked += HandleBtSaveClicked; //ComboBoxLang.Changed += HandleComboBoxLangChanged; // Accions del menú MenuItemImportPla.Activated += HandleMenuItemImportPlaActivated; MenuItemNewCathehory.Activated += HandleMenuItemNewCathehoryActivated; MenuItemImportGallery.Activated += HandleMenuItemImportGalleryActivated; MenuItemExportGallery.Activated += HandleMenuItemExportGalleryActivated; MenuItemExportOO.Activated += HandleMenuItemExportOOActivated; menuExportSVG.Activated += HandleMenuExportSVGActivated; MenuPreferences.Activated += HandleMenuPreferencesActivated; itemAbout.Activated += HandleItemAboutActivated; //InputTextName; //ComboBoxClass; //InputTextCaption; //btnFont // Interacció amb el pictograma BtImgDefault.Clicked += HandleBtImgDefaultClicked; InputComboTheme.Changed += HandleInputComboThemeChanged; //BtSelectImage; //PictImageToShow; //eventboxPict.ClientEvent += HandleEventboxPictClientEvent; //eventboxPict.ButtonPressEvent += new ButtonPressEventHandler(this.OnImageClick); //InputTextToSpeech; //FileChooseSound; BtSound.Clicked += HandleBtSoundClicked; BtSpeech.Clicked += HandleBtSpeechClicked; // Per quan canvie la imatge... //BtSelectImage.FileSet += HandleBtSelectImageFileSet; BtImgSel.Clicked += HandleBtImgSelClicked; BtSndSel.Clicked += HandleBtSndSelClicked; //FileChooseSound.FileSet += HandleFileChooseSoundFileSet; Preview.ExposeEvent += HandlePreviewExposeEvent; // Per modificar el preview si canvia el text o els colors... InputTextCaption.Changed += HandleInputTextCaptionChanged; btnFont.FontSet += HandleBtnFontFontSet; BtnFontColor.ColorSet += HandleBtnFontColorColorSet; BtnBackground.ColorSet += HandleBtnBackgroundColorSet; //RBTop.Clicked += HandleRBTopClicked; //RBBottom.Clicked += HandleRBBottomClicked; RBTop.Toggled += HandleRBTopToggled; RBBottom.Toggled += HandleRBBottomToggled; } void HandleItemAboutActivated (object sender, EventArgs e) { AboutDialog dlg=new AboutDialog(); dlg.ProgramName="LliureX Amic Pictogram Editor"; dlg.Version="2.0"; dlg.Comments="Pictogram Editor and Gallery Manager for LliureX Amic Pictographic Communicator"; dlg.Copyright="Copyright 2011. The LliureX Team.\n\n"; dlg.License="License: GPL-3\n\nThis program is free software; you can \n" + "redistribute it and/or modify it under \n" + "the terms of the GNU General Public \n" + "License as published by the Free Soft-\n" + "ware Foundation; either version 3, or \n" + "(at your option) any later version.\n\n\n"; dlg.Run(); dlg.Destroy(); } void HandleMenuExportSVGActivated (object sender, EventArgs e) { Export2SVG(false); } void Export2SVG(bool export2OO){ // Funció per exportar la galeria actual a una galeria de cliparts d'OpenOffice // El paràmetre export2OO indica si també s'exporta a OpenOffice o es deixa amb l'SVG Console.WriteLine(CatActual); if (CatActual==null||CatActual==""){ MessageDialog md = new MessageDialog (WinGallery , DialogFlags.DestroyWithParent, Gtk.MessageType.Error, ButtonsType.Ok, Mono.Unix.Catalog.GetString("You need to select a Category to import.")); md.Run(); md.Destroy(); } else{ Cathegory cat=MyGallery.GetPictogramsFrom(CatActual); // Comprovem que tinga pictogrames if (cat.GetPictograms().Count==0){ MessageDialog md = new MessageDialog (WinGallery , DialogFlags.DestroyWithParent, Gtk.MessageType.Error, ButtonsType.Ok, Mono.Unix.Catalog.GetString("There are no pictograms in the Gallery.")); md.Run(); md.Destroy(); } else { // Obrim el diàleg de conversió OOConvertDialog dlgnou=new OOConvertDialog(cat.GetPictograms(), export2OO); dlgnou.Modal=true; dlgnou.SetPosition(WindowPosition.CenterAlways); dlgnou.Show(); } } } void HandleMenuItemExportOOActivated (object sender, EventArgs e) { // Funció per exportar la galeria actual a una galeria de cliparts d'OpenOffice Export2SVG(true); } void HandleMenuPreferencesActivated (object sender, EventArgs e) { PreferencesDialog dlgnou=new PreferencesDialog(); dlgnou.Show(); } void HandleBtSpeechClicked (object sender, EventArgs e) { // Creem l'arxiu en funció de l'idioma i el text FileStream fs=null; StreamWriter sw=null; try{ if(File.Exists("/tmp/saytext.smc")) File.Delete("/tmp/saytext.smc"); fs = new FileStream("/tmp/saytext.smc", FileMode.CreateNew, FileAccess.Write); sw=new StreamWriter(fs, System.Text.Encoding.GetEncoding("iso-8859-1")); //Console.WriteLine(ComboBoxLang.ActiveText); //Console.WriteLine(this.CurrentPic.lang); TreeIter Myiter; string idioma="en_GB"; ComboBoxLang.Model.GetIterFirst(out Myiter); do { GLib.Value thisRow = new GLib.Value (); GLib.Value thisRow2 = new GLib.Value (); ComboBoxLang.Model.GetValue (Myiter, 1, ref thisRow); //Console.WriteLine("-----------Lang: "+thisRow.Val.ToString()); ComboBoxLang.Model.GetValue (Myiter, 0, ref thisRow2); //Console.WriteLine("Lang: "+thisRow2.Val); if ((thisRow2.Val as string).Equals(ComboBoxLang.ActiveText)) { Console.WriteLine("Lang: "+thisRow.Val.ToString()); idioma=thisRow.Val.ToString(); break; } } while (ComboBoxLang.Model.IterNext (ref Myiter)); if(idioma=="qcv_ES") if(Preferences.lang_voice=="male") sw.WriteLine("(voice_upc_ca_pau_hts)"); else sw.WriteLine("(voice_upc_ca_ona_hts)"); else if (idioma=="es_ES") if(Preferences.lang_voice=="male") sw.WriteLine("(voice_JuntaDeAndalucia_es_pa_diphone)"); else sw.WriteLine("(voice_JuntaDeAndalucia_es_sf_diphone)"); else sw.WriteLine("(voice_kal_diphone)"); // Ajustem la durada sw.WriteLine("(Parameter.set 'Duration_Stretch "+Preferences.speed_speech+")"); sw.WriteLine("(SayText \""+InputTextToSpeech.Text+"\")"); sw.Close(); // Execució del festival System.Threading.Thread thread; thread=null; System.Threading.ThreadStart tstart=delegate{ lliurex.utils.Commands.run("festival", "-b /tmp/saytext.smc"); //lliurex.utils.Commands.run("cat","saytext.smc | iconv -f utf-8 -t iso-8859-1| festival"); }; thread=new System.Threading.Thread(tstart); thread.Start(); } catch (Exception exc){ Console.WriteLine("Excepcio llegint el text: "+exc); if (sw!=null) sw.Close(); } } void HandleBtSoundClicked (object sender, EventArgs e) { string FileToPlay=""; if (File.Exists(Preferences.dir_audio_custom+"/"+BtSndSel.Label)) FileToPlay=Preferences.dir_audio_custom+"/"+BtSndSel.Label; else FileToPlay=Preferences.dir_audio+"/"+BtSndSel.Label; Console.WriteLine("Playing... "+FileToPlay); try{ //carga id_audio = server.LoadMedia(FileToPlay); //play server.Play(id_audio); }catch (Exception exc){ Console.WriteLine("Exception: "+exc); } } void HandleRBBottomToggled (object sender, EventArgs e) { SelectedPic.align="bottom"; //Console.WriteLine("Bottom"); DrawPreview(); } void HandleRBTopToggled (object sender, EventArgs e) { SelectedPic.align="top"; DrawPreview(); //Console.WriteLine("TOP"); } //void HandleComboBoxLangChanged (object sender, EventArgs e) //{ //Preferences.lang_code=ComboBox. //} void HandleBtnBackgroundColorSet (object sender, EventArgs e) { if (this.PictImageToShow.Pixbuf!=null) DrawPreview(); } void HandleBtnFontColorColorSet (object sender, EventArgs e) { if (this.PictImageToShow.Pixbuf!=null) DrawPreview(); } void HandleBtnFontFontSet (object sender, EventArgs e) { if (this.PictImageToShow.Pixbuf!=null) DrawPreview(); } void HandleInputTextCaptionChanged (object sender, EventArgs e) { if (this.PictImageToShow.Pixbuf!=null) DrawPreview(); } void HandleMenuItemExportGalleryActivated (object sender, EventArgs e) { DlgExportArchive dlgExport=new DlgExportArchive(MyGallery); dlgExport.Show(); } void HandleMenuItemImportGalleryActivated (object sender, EventArgs e) { FileChooserDialog dialog=new FileChooserDialog(Mono.Unix.Catalog.GetString("Select Archive "),WinGallery, Gtk.FileChooserAction.Open); dialog.AddButton("Cancel", ResponseType.Cancel); dialog.AddButton("Accept", ResponseType.Accept); //dialog.SetCurrentFolder(Directory); FileFilter ArxiusAgz=new FileFilter(); ArxiusAgz.AddPattern("*.agz"); dialog.AddFilter(ArxiusAgz); dialog.Modal=true; dialog.Response += HandleDialogOpenAgzResponse; dialog.Run(); } void HandleMenuItemNewCathehoryActivated (object sender, EventArgs e) { CreateNewCathegory(); } void HandleMenuItemImportPlaActivated (object sender, EventArgs e) { // Gestiona la importació d'arxius de Plaphoons //Gtk.FileChooserDialog dlg=new Gtk.FileChooserDialog("Select files...", WinGallery, FileChooserAction.Open, null); FileChooserDialog dialog=new FileChooserDialog("Select files to import...",WinGallery, Gtk.FileChooserAction.Open); dialog.AddButton("Cancel", ResponseType.Cancel); dialog.AddButton("Accept", ResponseType.Accept); dialog.SetCurrentFolder(Preferences.link_default_image); FileFilter ArxiusPla=new FileFilter(); ArxiusPla.AddPattern("*.pla"); dialog.AddFilter(ArxiusPla); dialog.SelectMultiple=true; // Cal que puga fer vàries seleccions!! //**************************************************************** dialog.Modal=true; dialog.Response += HandleDialogResponse; dialog.Run(); } void HandleDialogOpenAgzResponse (object o, ResponseArgs args) { if (args.ResponseId == Gtk.ResponseType.Accept){ Archiver.ImportArchive(((Gtk.FileChooserDialog)o).Filename); /* MessageDialog md = new MessageDialog (WinGallery, DialogFlags.DestroyWithParent, Gtk.MessageType.Error, ButtonsType.Ok, "1111111111111111111111"); md.Run(); md.Destroy(); */ // Una vegada importat, actualitzem la llista de galeries MyGallery=new Gallery(); // Tornem a llegir la galeria AddPictogramsToView(PictogramsActual); AddCathegoriesToView(); } ((Gtk.FileChooserDialog)o).Destroy(); } void HandleDialogResponse (object o, ResponseArgs args) { if (args.ResponseId == Gtk.ResponseType.Accept){ Cathegory cat=PlaConverter.Pla2Amic(((Gtk.FileChooserDialog)o).Filenames); if (cat!=null){ MyGallery.Add(cat); AddCathegoriesToView(); } } ((Gtk.FileChooserDialog)o).Destroy(); } void HandleBtSndSelClicked (object sender, EventArgs e) { string path; SelectedSoundFile=BtSndSel.Label; try{ ////if (this.BtImgSel.Label!=null) path=dir_audio+"/"+this.BtSndSel.Label; //if (this.BtImgSel.Label!=null) Console.WriteLine("Su puta madre del path vale...!=NULL "+this.BtIm); //if (this.BtSndSel.Label!=null) path=this.BtSndSel.Label; Console.WriteLine("PATHHHHHHHHH: "+Preferences.dir_audio+"/Default"); Console.WriteLine("PATHHHHHHHHH: "+Preferences.dir_audio+"/"+this.BtSndSel.Label); if (this.BtSndSel.Label!=null) path=Preferences.dir_audio+"/"+this.BtSndSel.Label; else path=Preferences.dir_audio+"/Default"; //if (SelectedSoundFile!=null) path=dir_audio+"/"+SelectedSoundFile; //else path=dir_audio; //SaveSoundWindow filedlg=new SaveSoundWindow(Preferences.dir_audio,Preferences.dir_audio_custom, this.BtSndSel.Label, Preferences.link_custom_audio, Preferences.link_default_audio); SaveSoundWindow filedlg=new SaveSoundWindow(this.BtSndSel.Label); filedlg.Show(); //Console.WriteLine("SelectedSoundFile="+SelectedSoundFile); //Console.WriteLine("Path="+path); //Console.WriteLine("File...="+dir_audio+"/"+SelectedSoundFile); //if(SelectedSoundFile!=path&&File.Exists(dir_audio+"/"+SelectedSoundFile)){ //if(SelectedSoundFile!=path) Console.WriteLine("No concorda el path!!!!!!!!!!!!!!!! "+SelectedSoundFile+" amb "+path); //if(!File.Exists(dir_audio SelectedSoundFile)) Console.WriteLine("No existeix "+SelectedSoundFile+"****************"); //if(!File.Exists(dir_audio+"/"+SelectedSoundFile)) Console.WriteLine("No existeix "+dir_audio+"/"+SelectedSoundFile+"********"); // PATCH if(SelectedSoundFile!=path&&(File.Exists(Preferences.dir_audio+"/"+SelectedSoundFile)|| // PATCH File.Exists(Preferences.dir_audio_custom+"/"+SelectedSoundFile))){ Console.WriteLine("SelectedSoundFile----------------"+SelectedSoundFile); Console.WriteLine("path----------------"+path); Console.WriteLine("dir_audio----------------"+SelectedSoundFile); if(File.Exists(SelectedSoundFile)) Console.WriteLine("exists"); Console.WriteLine("dir_audio:----------------"+Preferences.dir_audio+"/Default/"+SelectedSoundFile); if(File.Exists(Preferences.dir_audio+"/Default/"+SelectedSoundFile)) Console.WriteLine("exists"); Console.WriteLine("dir_audio_custom-:-----------"+SelectedSoundFile); if(File.Exists(SelectedSoundFile)) Console.WriteLine("exists"); Console.WriteLine("dir_audio_custom------------"+Preferences.dir_audio_custom+"/Custom/"+SelectedSoundFile); if(File.Exists(Preferences.dir_audio_custom+"/Custom/"+SelectedSoundFile)) Console.WriteLine("exists"); //if(SelectedSoundFile!=path&&(File.Exists(Preferences.dir_audio+"/DefaultAudioGallery/"+SelectedSoundFile)|| // File.Exists(Preferences.dir_audio_custom+"/CustomAudioGallery/"+SelectedSoundFile))){ if(SelectedSoundFile!=path&&(File.Exists(SelectedSoundFile)|| File.Exists(SelectedSoundFile))){ //if(SelectedSoundFile!=path&&File.Exists(SelectedSoundFile)){ //Console.WriteLine("Cal actualitzar la imatge: "+SelectedImageFile); //BtSelectImage.SetFilename(SelectedImageFile); SelectedSoundFile=SelectedSoundFile.Replace(Preferences.dir_audio+"/",""); // PATCH BtSndSel.Label=SelectedSoundFile; //SelectedPic.actionSound=dir_audio+SelectedSoundFile; SelectedPic.actionSound=SelectedSoundFile; } else { Console.WriteLine("Ha donat a cancel·lar: path="+path+" SelectedSoundFile: "+SelectedSoundFile); } //this.BtSelectImage.SetFilename(myfile); } catch (Exception exc){Console.WriteLine("Exception: "+exc); } } void HandleBtImgSelClicked (object sender, EventArgs e) { /* * Gestiona el clic sobre el botó per canviar la imatge. * * */ SeleccionaImatge(); } void SeleccionaImatge(){ string path; try{ // Si no hi ha imatge seleccionada, passem el directori de la galeria per defecte if (this.BtImgSel.Label!=null) path=Preferences.dir_img+"/"+this.BtImgSel.Label; else path=Preferences.dir_img; /*Console.WriteLine("----------------------------------"); Console.WriteLine("path="+path); Console.WriteLine("dir_img="+dir_img); Console.WriteLine("custom="+dir_img_custom); Console.WriteLine("imatge: "+this.BtImgSel.Label); Console.WriteLine("----------------------------------");*/ //SaveFileWindow filedlg=new SaveFileWindow(Preferences.dir_img, Preferences.dir_img_custom, this.BtImgSel.Label, Preferences.link_custom_image, Preferences.link_default_image); SaveFileWindow filedlg=new SaveFileWindow(this.BtImgSel.Label); filedlg.Show(); Console.WriteLine("path: "+path+" SelectedImage: *"+SelectedImageFile+"*"); if(SelectedImageFile!=path&&File.Exists(SelectedImageFile)){ Console.WriteLine("Cal actualitzar la imatge: "+SelectedImageFile); //BtSelectImage.SetFilename(SelectedImageFile); BtImgSel.Label=SelectedImageFile; ActualitzaImatge(); } else { Console.WriteLine("Ha donat a cancel·lar"); } } catch (Exception ex){ Console.WriteLine("Exception: "+ex); } } /*private void OnImageClick (object o, ButtonPressEventArgs args) { if (args.Event.Button==1){ try{ SeleccionaImatge(); / *string path; if (this.BtSelectImage.Filename!=null) path=this.BtSelectImage.Filename; else path=dir_img; SaveFileWindow filedlg=new SaveFileWindow(path); filedlg.Show(); Console.WriteLine("path: "+path+" SelectedImage: *"+SelectedImageFile+"*"); if(SelectedImageFile!=path&&File.Exists(SelectedImageFile)){ Console.WriteLine("Cal actualitzar la imatge: "+SelectedImageFile); BtSelectImage.SetFilename(SelectedImageFile); ActualitzaImatge(); } else { Console.WriteLine("Ha donat a cancel·lar"); } //Gdk.event //ObreBotoTriarImatge(); //BtSelectImage.SetFilename(BtSelectImage.Filename);* / } catch (Exception ex){ Console.WriteLine("Excepcio"+ex); } } }*/ /*void HandleEventboxPictClientEvent (object o, ClientEventArgs args) { //BtSelectImage.filename=BtSelectImage.Filename; Console.WriteLine("Clicked!!"); BtSelectImage.SetFilename(BtSelectImage.Filename); }*/ void HandleComboBoxThemeChanged (object sender, EventArgs e) { //Simplement refresquem les imatges de la vista d'icones if(PictogramsActual!=null){ AddPictogramsToView(PictogramsActual); } SetControlsPictogram(false); } /*void HandleFileChooseSoundFileSet (object sender, EventArgs e) { /*try{ Console.WriteLine("Passem pel botó de sò.. "+((Gtk.FileChooserButton)sender).Filename); string myfile=((Gtk.FileChooserButton)sender).Filename; // Console.WriteLine(this.FileChooseSound.Filename); // Cal eliminar la ruta... string [] path = this.FileChooseSound.Filename.Split(new Char [] {'/'}); string file=path[path.Length-1]; Console.WriteLine(file); //Console.WriteLine("Obtinc: "+Directory.GetCurrentDirectory()+"/"+dir_img+"/"+ file); Console.WriteLine("Obtinc: "+dir_audio +"/"+ file); SelectedPic.actionSound=file; //this.BtSelectImage.SetFilename(myfile); } catch (Exception exc){Console.WriteLine("Exception: "+exc); } * / }*/ void ActualitzaImatge(){ //Console.WriteLine("Passem pel botó .. "+((Gtk.FileChooserButton)sender).Filename); //string myfile=((Gtk.FileChooserButton)sender).Filename; //string myfile=BtSelectImage.Filename; // //string myfile=dir_img+"/"+BtImgSel.Label; /* Per eliminar el warning !!! string myfile; if(System.IO.File.Exists(Preferences.dir_img_custom+"/"+BtImgSel)) myfile=Preferences.dir_img_custom+"/"+BtImgSel.Label; else myfile=Preferences.dir_img+"/"+BtImgSel.Label; */ Console.WriteLine("+++++++++++++++++++++++++++++++++++++++++"+SelectedImageFile+"***********+"); //Console.WriteLine(this.BtSelectImage.Filename); // Cal eliminar la ruta... //string [] path = this.BtSelectImage.Filename.Split(new Char [] {'/'}); /*string [] path = this.BtImgSel.Label.Split(new Char [] {'/'}); string file=path[path.Length-1]; Console.WriteLine("*!*!*!*!*!*!*!*!**!*!*!*!*!*!*!**!*!*!*!*!*!*!*!*!*!"+file); */ string file=""; // Restem les rutes a la imatge, per saber si està a Cutom o a Default file=GeneralUtils.GetFilenameFrom(this.BtImgSel.Label, Preferences.dir_img_custom, Preferences.dir_img); Console.WriteLine("Canviant la imatge del tema: "+InputComboTheme.ActiveText+" a la imatge: "+file); SelectedPic.setImageTheme(file, InputComboTheme.ActiveText); RefreshImageTheme(); AddPictogramsToView(PictogramsActual); //AddCathegoriesToView(); //PictogramsActual=MyGallery.GetPictogramsFrom(cat_tmp); //this.BtSelectImage.SetFilename(myfile); Console.WriteLine("-----------------------------------------------------------"+SelectedImageFile); //BtSelectImage.SetFilename(SelectedImageFile); //string [] parts=SelectedImageFile.Split(new Char [] {'/'}); //BtImgSel.Label=parts[parts.Length-1]; BtImgSel.Label=GeneralUtils.GetFilenameFrom(SelectedImageFile, Preferences.dir_img_custom, Preferences.dir_img); Console.WriteLine(BtImgSel.Label); } /* void HandleBtSelectImageFileSet (object sender, EventArgs e) { ActualitzaImatge(); } */ void HandleInputComboThemeChanged (object sender, EventArgs e) { // Quan canviem el ComboBox del tema, carregarem la imatge que toca //string btimg=BtSelectImage.Filename; //Console.WriteLine("qqqqqqqqqqqqqqqqqqq"+ sender); //Console.WriteLine(">>>>"+btimg); RefreshImageTheme(); //Console.WriteLine("<<<<<"+btimg); } void HandlePreviewExposeEvent (object o, ExposeEventArgs args) { if (this.PictImageToShow.Pixbuf!=null) DrawPreview(); } void DrawPreview(){ Gtk.Image MyImage=this.PictImageToShow; //Gdk.GC backGc; //backGc = new Gdk.GC(Preview.GdkWindow); //backGc.RgbBgColor = new Gdk.Color (255, 255, 0); //Gdk.GC gc = Preview.Style.BlackGC; Gdk.GC gc=((Gtk.DrawingArea)Preview).Style.TextGC(Gtk.StateType.Normal); //Cairo.Context context = Gdk.CairoHelper.Create (((Gtk.DrawingArea)obj).GdkWindow); Cairo.Context context = Gdk.CairoHelper.Create (Preview.GdkWindow); int daX, daY, x, y; //MyImage.GdkWindow.GetSize(out x, out y); x=MyImage.Pixbuf.Width; y=MyImage.Pixbuf.Height; Preview.GdkWindow.GetSize(out daX, out daY); int posX=(daX/2)-(x/2); int posY=(daY/2)-(y/2); Console.WriteLine("("+x+","+y+")"); Console.WriteLine("("+daX+","+daY+")"); Console.WriteLine("("+posX+","+posY+")"); //context.Color=new Cairo.Color(1,1,0.5); double r=double.Parse((BtnBackground.Color.Red).ToString())/65535; double g=double.Parse((BtnBackground.Color.Green).ToString())/65535; double b=double.Parse((BtnBackground.Color.Blue).ToString())/65535; Console.WriteLine("("+BtnBackground.Color.Red+","+BtnBackground.Color.Green+","+BtnBackground.Color.Blue+")"); Console.WriteLine("("+r+","+g+","+b+")"); context.Color=new Cairo.Color(r,g,b); context.Rectangle(0,0,daX,daY); //Gradient pattern = new LinearGradient ( Cairo.Gradient pat = new Cairo.LinearGradient (posX, 0, posX, daY); pat.AddColorStop (0, new Cairo.Color (r,g,b)); pat.AddColorStop (1, new Cairo.Color (r*1.5,g*1.5,b*1.5)); context.Pattern=pat; context.FillPreserve(); //MyImage.Pixbuf.Pixels //MyImage.Pixbuf=MyImage.Pixbuf.ScaleSimple(100,100, Gdk.InterpType.Bilinear); Preview.GdkWindow.DrawPixbuf(gc, MyImage.Pixbuf, 0, 0,posX,posY, x,y, Gdk.RgbDither.Max , 0, 0); Pango.Layout layout; layout = new Pango.Layout(WinGallery.PangoContext); layout.Width = Pango.Units.FromPixels(100); layout.Wrap = Pango.WrapMode.Word; layout.Alignment = Pango.Alignment.Left; layout.FontDescription = Pango.FontDescription.FromString(btnFont.FontName); //Console.WriteLine(Pango.FontDescription.FromString("btnFont.FontName")); //BtnFontColor.Color layout.SetMarkup("" + InputTextCaption.Text+ ""); int textX, textY; layout.GetPixelSize(out textX, out textY); Console.WriteLine("("+textX+","+textY+")"); if (SelectedPic.align=="top") Preview.GdkWindow.DrawLayout (Preview.Style.TextGC (StateType.Normal), daX/2-textX/2, 15, layout); else Preview.GdkWindow.DrawLayout (Preview.Style.TextGC (StateType.Normal), daX/2-textX/2, daY-15-textY, layout); ((IDisposable)context.Target).Dispose(); ((IDisposable)context).Dispose(); } void RefreshImageTheme(){ if(SelectedPic!=null){ string tema=this.InputComboTheme.ActiveText; string img_source=SelectedPic.getImageFromTheme(tema); // if(SelectedPic.getImageFromTheme(tema)==null) // Console.WriteLine("El pict actual de "+ tema +" te la imatge: "+SelectedPic.getImageFromTheme(tema)); /* * JA NO S'USA CURRENTPIC * if(CurrentPic!=null){ string tema=this.InputComboTheme.ActiveText; string img_source=CurrentPic.getImageFromTheme(tema); Console.WriteLine("El pict actual de "+ tema +" te la imatge: "+CurrentPic.getImageFromTheme(tema)); */ // I actualitzem la imatge if (img_source==""||img_source==null) { SelectedPic.setImageTheme(Preferences.dir_default+"/undefined.png", tema); //Console.WriteLine("NOOOOOOOOOOOOOOOOOOOOOOO"); img_source="undefined.png"; } if (System.IO.File.Exists(Preferences.dir_img_custom+"/"+img_source)) { Console.WriteLine("Trobe "+Preferences.dir_img_custom+"/"+img_source); MiImage = new Gtk.Image(Preferences.dir_img_custom+"/"+img_source); }else if (System.IO.File.Exists(Preferences.dir_img+"/"+img_source)) { Console.WriteLine("Trobe "+Preferences.dir_img+"/"+img_source); MiImage = new Gtk.Image(Preferences.dir_img+"/"+img_source); } else { Console.WriteLine("No trobe "+Preferences.dir_img+"/"+img_source); MiImage = new Gtk.Image(Preferences.dir_default+"/notfound.png"); } int new_width=125; int new_height=125; MiImage.Pixbuf = MiImage.Pixbuf.ScaleSimple(new_width, new_height, Gdk.InterpType.Bilinear); this.PictImageToShow.Pixbuf=MiImage.Pixbuf; DrawPreview(); // Actualitzem també el nom de la imatge al Botó de selecció d'imate // string dir_actual=Directory.GetCurrentDirectory(); // string complete_filename=dir_actual+"/"+dir_img+"/"+img_source; // string complete_filename=dir_img+"/"+img_source; //BtSelectImage.SetCurrentFolder(dir_actual+"/"+dir_img); //BtSelectImage.SetFilename(img_source); //Console.WriteLine("Setting: "+BtSelectImage.Settings.ToString()); //this.BtSelectImage.SetFilename(complete_filename); this.BtImgSel.Label=img_source; // Console.WriteLine("Canviem a: "+ complete_filename); // if (File.Exists(complete_filename)) Console.WriteLine ("és un arxiu..."); // else Console.WriteLine ("NO és un arxiu..."); // Console.WriteLine("i val: "+this.BtSelectImage.GetType()+this.BtSelectImage.Filename); /*///////////////// iconView.SelectedItems.SetValue(MiImage, 0); ACI M'HE QDAT!! //Cat.cathegoryname, pict.pictname, MiPixbuf,true*/ } } void HandleBtImgDefaultClicked (object sender, EventArgs e) { if (CatActual!=""&&ComboBoxClass.ActiveText!=""){ /* //Cathegory cat; //cat=PictogramsActual.GetCathegory(CatActual); //Gdk.Color color=(PictogramsActual.GetCathegory(CatActual)).BackgroundColor; Cathegory NewCat=MyGallery.GetPictogramsFrom(ComboBoxClass.ActiveText); Gdk.Color color=NewCat.BackgroundColor; //Gdk.Color color=PictogramsActual.BackgroundColor; //Console.WriteLine("Estem en "+CatActual+" Color: "+color); BtnBackground.Color=color; */ Console.WriteLine("CAT:"+CatActual); BtnBackground.Color=MyGallery.GetCatColor(CatActual); } } public ResponseType Alert(string text){ MessageDialog md = new MessageDialog (WinGallery, DialogFlags.DestroyWithParent, Gtk.MessageType.Error, ButtonsType.Ok, text); ResponseType result = (ResponseType)md.Run(); md.Destroy(); return result; } public string TransformColor(string gtkcolor){ /* * Torna un string tipus #rrggbb a partir d'un gtkcolor * * */ string [] color = gtkcolor.Split(new Char [] {':'}); if (color.Length<1) return "#000000"; else{ string [] components=color[1].Split(new Char [] {'/'}); if (components.Length!=3) return "#000000"; else{ string r,g,b; if (components[0].Length>2) r=components[0].Substring(0,2); else r="0"+components[0].Substring(0,1); if (components[1].Length>2) g=components[1].Substring(0,2); else g="0"+components[1].Substring(0,1); if (components[2].Length>2) b=components[2].Substring(0,2); else b="0"+components[2].Substring(0,1); return "#"+r+g+b; } } } } }