using System; using Gtk; using Glade; using NDesk.DBus; namespace AmicEditor { [NDesk.DBus.Interface("net.Lliurex.Media.AudioServer")] /*public interface IAudioServer { int LoadMedia(string filename); void Play(int id); void Stop(int id); }*/ public class SaveSoundWindow2 : Dialog { //[Widget] Gtk.ColorButton CatFontColor; [Widget] Gtk.Dialog ChooseFile; //[Widget] Gtk.Widget dialogvbox1; //[Widget] Gtk.FileChooserWidget dialogvbox1; [Widget] Gtk.Button btCancel; [Widget] Gtk.Button BtOk; [Widget] Gtk.Button BtPlay; [Widget] Gtk.Button BtStop; //[Widget] Gtk.FileChooserWidget filechooserwidget1; [Widget] Gtk.FileChooserWidget SoundSelectorWidget=new Gtk.FileChooserWidget(Gtk.FileChooserAction.Open); // Thread per execurar l'mplayer //System.Threading.Thread thread; string orig_audio=""; // aUDIO Original string pathGeneral=""; string pathCustom=""; string filename=""; string linkDefault=""; string linkCustom=""; int id_audio=-1; IAudioServer server; //public SaveSoundWindow (string _pathDefault, string _pathCustom, string _filename, string link_custom, string link_default) /////////////// ) /////////////// public SaveSoundWindow2 (string _filename) { Application.Init(); Glade.XML gxml = new Glade.XML(null, "SaveSoundWindow.glade", "ChooseFile", null); //Console.WriteLine(path); //thread=null; gxml.Autoconnect(this); //orig_audio=path; // 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); pathGeneral=Preferences.dir_audio; pathCustom=Preferences.dir_audio_custom; filename=_filename; // Links a les carpetes d'audio linkDefault=Preferences.link_custom_audio; linkCustom=Preferences.link_default_audio; /*linkDefault=link_default;Preferences.link_custom_audio linkCustom=link_custom;*/ // Comprovem si el so és a la galeria Custom if(System.IO.File.Exists(pathCustom+"/"+filename)) orig_audio=pathCustom+"/"+filename; // Audio Original Actualitzat else //if(System.IO.File.Exists(pathGeneral+"/"+filename)) // En cas contrari busquem a la galeria general orig_audio=pathGeneral+"/"+filename; // so Original Actualitzat /*else { orig_img=pathGeneral+"/"; // imatge Original Actualitzada }*/ // Afegim els enllaços SoundSelectorWidget.AddShortcutFolder(linkCustom); SoundSelectorWidget.AddShortcutFolder(linkDefault); //filechooserwidget1.SetCurrentFolder(path); SoundSelectorWidget.SetFilename(orig_audio); // Afegit el filtre d'audio Gtk.FileFilter filter=new Gtk.FileFilter(); filter.Name="Audio Files"; filter.AddPattern("*.mp3"); filter.AddPattern("*.ogg"); filter.AddPattern("*.wav"); SoundSelectorWidget.AddFilter(filter); btCancel.Clicked += HandleBtCancelClicked; BtOk.Clicked += HandleBtOkClicked; BtPlay.Clicked += HandleBtPlayClicked; BtStop.Clicked += HandleBtStopClicked; } void HandleBtStopClicked (object sender, EventArgs e){ if (id_audio!=-1) { try{ server.Stop(id_audio); }catch (Exception ex){ Console.WriteLine("Exception: "+ex); } } } void HandleBtPlayClicked (object sender, EventArgs e) { // Magic AudioMagic=new Magic(); Console.WriteLine("Play... "+SoundSelectorWidget.Filename); // if(AudioMagic.isAudioFile(SoundSelectorWidget.Filename)) // Console.WriteLine(SoundSelectorWidget.Filename+" és un arxiu d'audio!"); // else Console.WriteLine(SoundSelectorWidget.Filename+" NO és un arxiu d'àudio!"); if(SoundSelectorWidget.Filename!=null){ Console.WriteLine(SoundSelectorWidget.Filename); try{ //carga id_audio = server.LoadMedia(SoundSelectorWidget.Filename); //play server.Play(id_audio); }catch (Exception exc){ Console.WriteLine("Exception: "+exc); } } } void HandleBtOkClicked (object sender, EventArgs e) { //Magic AudioMagic=new Magic(); //if(AudioMagic.isAudioFile(SoundSelectorWidget.Filename)) //{ // Si és un arxiu d'audio vàlid, l'associa al pictograma try{ Console.WriteLine(SoundSelectorWidget.Filename.Substring(0,SoundSelectorWidget.Filename.LastIndexOf("/"))); Console.WriteLine(pathGeneral); Console.WriteLine(SoundSelectorWidget.Filename.Substring(0,SoundSelectorWidget.Filename.LastIndexOf("/"))); Console.WriteLine(pathCustom); if((SoundSelectorWidget.Filename.Substring(0,SoundSelectorWidget.Filename.LastIndexOf("/"))!=pathGeneral)&& (SoundSelectorWidget.Filename.Substring(0,SoundSelectorWidget.Filename.LastIndexOf("/"))!=pathCustom)) { // Obtenim les rutes i els noms dels arxius int pos_ini_file=SoundSelectorWidget.Filename.LastIndexOf("/"); int long_total=SoundSelectorWidget.Filename.Length; int long_file=long_total-pos_ini_file; string orig_filename=SoundSelectorWidget.Filename.Substring(pos_ini_file,long_file); //string dst_path=orig_audio.Substring(0,orig_audio.LastIndexOf("/")); string dst_path=pathCustom; // Copiarem a la galeria... // Veiem si ha triat un fitxer de fora que ja està dins la galeria... if (System.IO.File.Exists(dst_path+orig_filename)){ MessageDialog md = new MessageDialog (ChooseFile, DialogFlags.DestroyWithParent, MessageType.Warning, ButtonsType.YesNo, Mono.Unix.Catalog.GetString("The audio file is already in the Custom Gallery. Do you want to overwrite it?")); ResponseType result = (ResponseType)md.Run(); md.Destroy(); if (result==ResponseType.Yes){ // Si diu que si, eliminem l'arxiu i el tornem a copiar System.IO.File.Delete(dst_path+orig_filename); Console.WriteLine("Copiant "+SoundSelectorWidget.Filename+" a "+dst_path+orig_filename); System.IO.File.Copy(SoundSelectorWidget.Filename, dst_path+orig_filename); // I l'actualitzem i tanquem la finestra //AmicEditor.SelectedSoundFile=dst_path+orig_filename; AmicEditor.SelectedSoundFile=orig_filename.Substring(1, orig_filename.Length-1); Application.Quit(); ChooseFile.Destroy(); } } else { // Si no existeix, preguntem si vol copiar-lo (*1) MessageDialog md = new MessageDialog (ChooseFile, DialogFlags.DestroyWithParent, MessageType.Question, ButtonsType.YesNo, Mono.Unix.Catalog.GetString("The audio file is not included in the Custom Gallery. Do you want to import it there?")); ResponseType result = (ResponseType)md.Run(); md.Destroy(); if (result==ResponseType.Yes){ // Si vol importar-la, la copiem a la galeria Console.WriteLine("Copiant "+SoundSelectorWidget.Filename+" a "+dst_path+orig_filename); System.IO.File.Copy(SoundSelectorWidget.Filename, dst_path+orig_filename); // I l'actualitzem i tanquem la finestra //AmicEditor.SelectedSoundFile=dst_path+orig_filename; AmicEditor.SelectedSoundFile=orig_filename.Substring(1, orig_filename.Length-1); Application.Quit(); ChooseFile.Destroy(); } } // del else (*1) } else { // Si és un audio de la galeria, l'actualitza i tanca la finestra // AmicEditor.SelectedSoundFile=SoundSelectorWidget.Filename; // AmicEditor.SelectedSoundFile=SoundSelectorWidget.Filename; int longitud=SoundSelectorWidget.Filename.Length; int pos_ini=SoundSelectorWidget.Filename.LastIndexOf("/"); // Agafem el nom... AmicEditor.SelectedSoundFile=SoundSelectorWidget.Filename.Substring(pos_ini+1, longitud-(pos_ini+1)); Application.Quit(); ChooseFile.Destroy(); } } catch(Exception ex){ Console.WriteLine("LliureX-Amic Exception: "+ex); //} // del if MagicAudio... /*string [] path = SoundSelectorWidget.Filename.Split(new Char [] {'/'}); Console.WriteLine("Filename: "+path[path.Length-1]); AmicEditor.SelectedSoundFile=path[path.Length-1]; Application.Quit(); ChooseFile.Destroy(); */ } /*else { // ELSE DEL IF MAGICNUMBER... // Si no és un arxiu d'audio vàlid, informa l'usuari MessageDialog md = new MessageDialog (ChooseFile, DialogFlags.DestroyWithParent, MessageType.Warning, ButtonsType.Close, Mono.Unix.Catalog.GetString("You need to select a valid audio file.")); md.Run(); md.Destroy(); }*/ } void HandleBtCancelClicked (object sender, EventArgs e) { Application.Quit(); ChooseFile.Destroy(); } public new void Show(){ ChooseFile.ShowAll(); Application.Run(); } } }