websiteWebsite
biblix Biblix
Biblix est une application de gestion de bibliothéque personnelle

 

Browse the code

Revision log Information on the revision
Revision: 20 (differences)
Author: LordPhoenix
Log message: * Biblix/winBiblix.cs: Corrections mineures du code.
Ajout des fichiers Makefile généré par Monodevelop pour pouvoir compiler sans monodevelop
Change revision:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551
// winBiblix.cs
//
//  Copyright (C) 2007 BOUTRY Arnaud arnaud@lordphoenix.info
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; 
// version 2.1 of the License.
//
// This library 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
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
//
//
 
using System;
using System.Collections;
using Gtk;
using Mono.Unix;
 
namespace biblix
{
        public enum biblixaction
        {
                bxnone,
                bxadd,
                bxedit,
                bxdelete,
                bxnotedit
        }
        public partial class winBiblix : Gtk.Window
        {
                private booklist mybase;
                private biblixaction currentaction = biblixaction.bxnone;
                private book workbook,oldbook;
                
                //Element de construction du menu
                private ActionGroup group;
                private UIManager uim;
                private ActionEntry[] actionlist;
                private string uixml=
                        "<menubar>\n"+
                                "<menu name=\"mnubilibx\" action=\"actmnubiblix\"> \n"+
                                        "<menuitem name=\"mnuitAdd\" action=\"actAddBook\" />\n"+
                                        "<menuitem name=\"mnuitSave\" action=\"actSaveBook\" />\n"+
                                        "<menuitem name=\"mnuitUndo\" action=\"actUndo\" />\n"+
                                        "<menuitem name=\"mnuitDelete\" action=\"actDeleteBook\" />\n"+
                                        "<separator name=\"sep1\" />\n"+
                                        "<menuitem name=\"mnuitQuit\" action=\"actQuit\" />\n"+
                                "</menu>\n"+
                                "<menu name=\"mnuAide\" action=\"actmnuAide\" > \n"+
                                        "<menuitem name=\"mnuitAbout\" action=\"actAbout\" />\n"+
                                "</menu>\n"+
                        "</menubar>\n"+
                        "<toolbar name=\"maintool\" >\n"+
                                "<toolitem name=\"tlbAdd\" action=\"actAddBook\" />\n"+
                                "<toolitem name=\"tlbSave\" action=\"actSaveBook\" />\n"+
                                "<toolitem name=\"tlbUndo\" action=\"actUndo\" />\n"+
                                "<toolitem name=\"tlbDelete\" action=\"actDeleteBook\" />\n"+
                                "<separator name=\"tlbsep\" />\n"+
                                "<toolitem name=\"tlbQuit\" action=\"actQuit\" />\n"+
                        "</toolbar>";
                public winBiblix() : base(Gtk.WindowType.Toplevel)
                {
                        this.Build();
                        Mono.Unix.Catalog.Init("i8n1","./locale");
                        //Construction barre d'outil et menu
                        actionlist =  new ActionEntry[]
                        {
                                new ActionEntry("actmnubiblix",null,"_Biblix",null,null,null),
                                new ActionEntry("actmnuAide",null,"_Aide",null,null,null),
                                new ActionEntry("actAddBook",Stock.Add,"Ajouter",null,null,new EventHandler(actAddBookActivated)),
                                new ActionEntry("actSaveBook",Stock.Save,"_Enregistrer",null,null,new EventHandler(actSaveBookActivated)),
                                new ActionEntry("actUndo",Stock.Undo,"Annuler",null,null,new EventHandler(actUndoActivated)),
                                new ActionEntry("actDeleteBook",Stock.Delete,"Supprimer",null,null,new EventHandler(actDeleteBookActivated)),
                                new ActionEntry("actQuit",Stock.Quit,"_Quitter",null,null,new EventHandler(actQuitActivated)),
                                new ActionEntry("actAbout",Stock.About,"A _Propos",null,null,new EventHandler(actAboutActivated))
                        };
                        group = new ActionGroup("MainActions");
                        group.Add(actionlist);
                        group.GetAction("actSaveBook").Sensitive = false;
                        group.GetAction("actUndo").Sensitive = false;
                        uim = new UIManager();
                        uim.AddWidget += new AddWidgetHandler(OnAddWidget);
                        uim.InsertActionGroup(group,0);
                        uim.AddUiFromString(uixml);
                        
                        //Ouverture fichier de base de données
                        string filepath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
                        filepath +="/.biblix/booklist.blix";
                        mybase = new booklist(filepath);
                        
                        ListStore modBooklist = new ListStore(typeof(book));
                        trvBooklist.AppendColumn(Catalog.GetString("Livres"),new CellRendererText(),new Gtk.TreeCellDataFunc(RenderTitle));
                        trvBooklist.Model = modBooklist;
                        trvBooklist.Selection.Changed += new EventHandler(SelectedBookChange);
                        
                        //initialisation de la liste des genres
                        foreach(string genre in mybase.GetGenreList())
                                cbxListGenre.AppendText(genre);
                        
                        //Initialisation de la liste des sources
                        foreach (string source in mybase.GetSourcesList())
                                cbxSource.AppendText(source);
                        
                        txtComment.Buffer.Changed += OnEditBook;
                        txtSynopsis.Buffer.Changed += OnEditBook;
                        ShowBookList();
                }
                
                protected void OnAddWidget(object sender,AddWidgetArgs args)
                {
                        args.Widget.Show();
                        mnuBox.PackStart(args.Widget,false,true,0);
                }
                
                private void RenderTitle(Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
                {
                        book curbook =(book)model.GetValue(iter,0);
                        (cell as Gtk.CellRendererText).Text=curbook.titre;
                }
                
                private void ShowBookList()
                {
                        (trvBooklist.Model as ListStore).Clear();
                        IEnumerator i = mybase.getidlist().GetEnumerator();
                        while(i.MoveNext())
                        {
                                book curbook = mybase.getbook(i.Current.ToString());
                                if (curbook!=null)
                                        (trvBooklist.Model as ListStore).AppendValues(curbook);
                        }
                }
                
                private void ShowBookDetails(book currentbook)
                {
                        currentaction = biblix.biblixaction.bxnotedit;
                        entAuthor.Text="";
                        entTitle.Text="";
                        entSerieTitle.Text="";
                        entPublishYear.Text="";
                        cbxListGenre.Active=-1;
                        cbxNote.Active=-1;
                        cbxNote.Entry.Text="";
                        entVolume.Text="";
                        ckbReadBook.Active=false;
                        ckbPret.Active=false;
                        cbxSource.Active=-1;
                        txtComment.Buffer.Clear();
                        txtSynopsis.Buffer.Clear();
                        if (currentbook != null)
                        {
                                entAuthor.Text = currentbook.auteur;
                                entTitle.Text = currentbook.titre;
                                entSerieTitle.Text = currentbook.serie;
                                cbxNote.Active = currentbook.note;
                                if (currentbook.volume==0)
                                        entVolume.Text="";
                                else
                                        entVolume.Text=currentbook.volume.ToString();
                                ckbReadBook.Active = currentbook.lu;
                                ckbPret.Active = currentbook.pret;
                                txtComment.Buffer.Text = currentbook.commentaire;
                                txtSynopsis.Buffer.Text = currentbook.resume;
                                entPublishYear.Text = currentbook.publishyear;
                                
                                if (currentbook.shortdate!="01/01/0001")                                        
                                        lblDate.LabelProp = currentbook.longdate;
                                else 
                                        lblDate.LabelProp = Catalog.GetString("Sélectionnez une date");
 
                                int index = -1;
                                if (!String.IsNullOrEmpty(currentbook.genre))
                                {
                                        string searchgenre ="";
                                        ListStore listegenremodel = (ListStore)cbxListGenre.Model;
                                        System.Collections.IEnumerator i = listegenremodel.GetEnumerator();
                                        while ((i.MoveNext())&(searchgenre !=currentbook.genre))
                                        {
                                                object[] row = (System.Object[])i.Current;
                                                searchgenre = row[0].ToString();
                                                index +=1;
                                        }
                                }
                                cbxListGenre.Active = index;
                                
                                int indexsource = -1;
                                if(!String.IsNullOrEmpty(currentbook.source))
                                        {
                                        ListStore listesourcemodel = (ListStore)cbxSource.Model;
                                        IEnumerator j = listesourcemodel.GetEnumerator();
                                        string searchsource ="";
                                        while ((j.MoveNext())&(searchsource != currentbook.source))
                                        {
                                                object[] row =(System.Object[])j.Current;
                                                searchsource = row[0].ToString();
                                                indexsource+=1;
                                        }
                                        }
                                cbxSource.Active = indexsource;
                        }
                        currentaction = biblix.biblixaction.bxnone;
                }
                
                private void savebook()
                {
                        switch (currentaction)
                        {
                                case biblix.biblixaction.bxadd:
                                        mybase.addbook(workbook);
                                        break;
                                case biblix.biblixaction.bxedit :
                                        mybase.updatebook(workbook);
                                        break;
                        }
                        group.GetAction("actSaveBook").Sensitive = false;
                        group.GetAction("actUndo").Sensitive = false;
                        currentaction = biblixaction.bxnone;
                }
                
                
                //Action management methods
                protected void actAddBookActivated(object sender , EventArgs args)
                {
                        if (currentaction == biblixaction.bxnone)
                        {
                                dlgAddBook dlg = new dlgAddBook(mybase);
                                ResponseType result = (ResponseType)dlg.Run();
                                if (result==ResponseType.Ok)
                                {
                                        book newbook = dlg.newbook;
                                        mybase.addbook(newbook);
                                        this.ShowBookList();
                                }
                                dlg.Hide();
                                dlg.Destroy();
                                
                        }
                        else 
                        {
                                MessageDialog dlg = new MessageDialog(this,DialogFlags.DestroyWithParent,MessageType.Question,
                                                                      ButtonsType.YesNo,Catalog.GetString("Des modification sont en cours voulez vous les enregistrer?"));
                                if (dlg.Run()==(int)ResponseType.Yes)
                                {
                                        savebook();
                                }
                                dlg.Hide();
                                dlg.Destroy();
                        }
                }
                
                protected void actSaveBookActivated(object sender , EventArgs args)
                {
                        savebook();
                        oldbook=null;
                }
                
                protected void actUndoActivated(object sender , EventArgs args)
                {
                        switch (currentaction)
                        {
                                case biblixaction.bxedit:
                                        workbook = oldbook;
                                        ShowBookDetails(workbook);
                                        currentaction = biblixaction.bxnone;
                                        break;
                                case biblixaction.bxadd:
                                        TreeIter iter;
                                        trvBooklist.Selection.GetSelected(out iter);
                                        (trvBooklist.Model as ListStore).Remove(ref iter);
                                        ShowBookDetails(null);
                                        workbook = null;
                                        break;
                        }
                        oldbook = null;
                        group.GetAction("actSaveBook").Sensitive = false;
                        group.GetAction("actUndo").Sensitive = false;
                        currentaction = biblixaction.bxnone;
                }
                
                protected void actDeleteBookActivated(object sender , EventArgs args)
                {
                        if (currentaction != biblixaction.bxnone)
                        {
                                MessageDialog dlg = new MessageDialog(this,DialogFlags.DestroyWithParent,MessageType.Warning,
                                                                      ButtonsType.Close,"Attention des modifications sont en cours Enregistrez les ou annulez les avant de faire autre chose");
                                dlg.Run();
                                dlg.Hide();
                                dlg.Destroy();
                        }
                        else
                        {
                                MessageDialog dlg = new MessageDialog(this,DialogFlags.DestroyWithParent,MessageType.Question,
                                                                      ButtonsType.OkCancel,"Voulez vous vraiment supprimer le livre \"{0}\" de votre bibliothèque ?",workbook.titre);
                                if ((ResponseType)dlg.Run()==ResponseType.Ok)
                                {
                                        bool result = mybase.deletebook(workbook.id);
                                        if (result)
                                                workbook = null;
                                        ShowBookList();
                                        ShowBookDetails(workbook);
                                }
                                dlg.Hide();
                                dlg.Destroy();
                        }
                }
                
                protected void actQuitActivated(object sender , EventArgs args)
                {
                        if(currentaction == biblixaction.bxedit)
                        {
                                MessageDialog dlg = new MessageDialog(this,DialogFlags.DestroyWithParent,MessageType.Question,
                                                                      ButtonsType.YesNo,Catalog.GetString("Des modifications ont été effectuées voulez vous les sauvegarder avant de Quitter?"));
                                ResponseType result = (ResponseType)dlg.Run();
                                if (result == ResponseType.Yes)
                                        savebook();
                                
                                dlg.Hide();
                                dlg.Destroy();
                        }
                        Application.Quit();
                }
 
                protected void actAboutActivated(object sender , EventArgs args)
                {
                        Gtk.AboutDialog.SetUrlHook(new Gtk.AboutDialogActivateLinkFunc(openaboutlink));
                        Gtk.AboutDialog about = new AboutDialog();
                        about.Authors=new string[] {"BOUTRY Arnaud <arnaud@lordphoenix.info>"};
                        about.Artists = new string[] {Catalog.GetString("Les icônes viennent du site : http://www.famfamfam.com")};
                        about.Name="Biblix";
                        about.Version = "0.2";
                        about.LogoIconName="Biblix";
                        about.Copyright=" (c) BOUTRY Arnaud 2007"; 
                        about.Website="http://biblix.lordphoenix.info";
                        about.Comments=Catalog.GetString("Gérer facilement votre collection de livres");
                        about.WebsiteLabel=Catalog.GetString("Site web");
            about.License=Catalog.GetString("Ce logiciel est disponible sous licence GNU/GPL V2 \n voir le fichier COPYING");
                        
                        about.Run();
                        about.Hide();
                        about.Destroy();
                }
                        
                
                //Component event management methods
                protected virtual void SelectedBookChange(object sender, EventArgs args)
                {
                        switch (currentaction)
                        {
                                case biblixaction.bxedit:
                                        MessageDialog dlg = new MessageDialog(this,Gtk.DialogFlags.DestroyWithParent,
                                                                              Gtk.MessageType.Question,Gtk.ButtonsType.YesNo,
                                                                              String.Format(Catalog.GetString("Des modifications ont été apportées au livre ,{0} voulez vous les enregistrer?"),
                                                                              workbook.titre));
                                        ResponseType result = (ResponseType)dlg.Run();
                                        if (result==ResponseType.Yes)
                                        {
                                                mybase.updatebook(workbook);
                                                group.GetAction("actSaveBook").Sensitive = false;
                                                group.GetAction("actUndo").Sensitive = false;
                                                currentaction = biblixaction.bxnone;
                                        }
                                        else 
                                        {
                                                workbook = oldbook;
                                                ShowBookDetails(workbook);
                                            group.GetAction("actSaveBook").Sensitive = false;
                                                group.GetAction("actUndo").Sensitive = false;
                                                currentaction = biblixaction.bxnone;
                                        }
                                        dlg.Hide();
                                        dlg.Destroy();
                                        break;
                                case biblixaction.bxadd :
                                        break;
                                
                                case biblixaction.bxnone:
                                        TreeIter selectediter;
                                        if (trvBooklist.Selection.GetSelected(out selectediter))
                                        {
                                                book selectedbook = (book)((trvBooklist.Model as ListStore).GetValue(selectediter,0));
                                                workbook = selectedbook;
                                                ShowBookDetails(selectedbook);
                                        }
                                        else ShowBookDetails(null);
                                        break;
                        }
                }
 
                protected virtual void OnDeleteEvent (object o, Gtk.DeleteEventArgs args)
                {
                        Application.Quit ();
                        args.RetVal = true;
                }
 
                protected virtual void OnCkbFilterClicked (object sender, System.EventArgs e)
                {
                        cbxFilterItem.Sensitive=ckbFilter.Active;
                        cbxFilterValue.Sensitive=ckbFilter.Active;
                        if (!ckbFilter.Active)
                        {
                                cbxFilterItem.Active=-1;
                                cbxFilterValue.Active=-1;
                                (cbxFilterValue.Model as ListStore).Clear();
                                ShowBookList();
                        }
                }
 
                protected virtual void OnEditBook (object sender, System.EventArgs e)
                {
                        if(workbook != null)
                        {
                                if (currentaction != biblix.biblixaction.bxnotedit)
                                {
                                        if (currentaction != biblixaction.bxadd)
                                                currentaction = biblix.biblixaction.bxedit;
                                        if (oldbook==null)
                                                oldbook = (book)workbook.Clone();// Ne sauvegarder que si cela n'a pas déjà été fait.
                                        workbook.titre = entTitle.Text;
                                        workbook.auteur = entAuthor.Text;
                                        workbook.genre = cbxListGenre.ActiveText;
                                        workbook.serie = entSerieTitle.Text;
                                        if (entVolume.Text=="")
                                                workbook.volume=0;
                                        else 
                                                workbook.volume = Int32.Parse(entVolume.Text);
                                        workbook.note=cbxNote.Active;
                                        workbook.lu = ckbReadBook.Active;
                                        workbook.source = cbxSource.ActiveText;
                                        workbook.pret = ckbPret.Active;
                                        workbook.resume = txtSynopsis.Buffer.Text;
                                        workbook.commentaire = txtComment.Buffer.Text;
                                        workbook.publishyear = entPublishYear.Text;
                                        group.GetAction("actSaveBook").Sensitive = true;
                                        group.GetAction("actUndo").Sensitive = true;
                                }
                        }
                }
 
                protected virtual void OnBtnDateClicked (object sender, System.EventArgs e)
                {
                        biblix.dlgDateSelect dlgdate = new dlgDateSelect();
                        dlgdate.Run();
                        lblDate.LabelProp = dlgdate.SelectedDate.ToLongDateString();
                        workbook.shortdate = dlgdate.SelectedDate.ToShortDateString();
                        dlgdate.Hide();
                        dlgdate.Destroy();
                        currentaction= biblixaction.bxedit;
                        group.GetAction("actSaveBook").Sensitive = true;
                        group.GetAction("actUndo").Sensitive = true;
                }
 
                protected virtual void OnBtnAutreGenreClicked (object sender, System.EventArgs e)
                {
                        biblix.dlgNewRefValue dlg = new dlgNewRefValue(Catalog.GetString("Ajout d'un genre littéraire"));
                        ResponseType result = (ResponseType)dlg.Run();
                        if (result==Gtk.ResponseType.Ok)
                                cbxListGenre.AppendText(dlg.refvalue);
                        dlg.Hide();
                        dlg.Destroy();
                }
 
                protected virtual void OnBtnAddSourceClicked (object sender, System.EventArgs e)
                {
                        biblix.dlgNewRefValue dlg = new dlgNewRefValue(Catalog.GetString("Ajout d'une source supplémentaire"));
                        ResponseType result = (ResponseType)dlg.Run();
                        if (result == ResponseType.Ok)
                                cbxSource.AppendText(dlg.refvalue);
                        dlg.Hide();
                        dlg.Destroy();
                }
 
 
                protected void openaboutlink(Gtk.AboutDialog dialog, string link)
                {
                        Gnome.Url.Show(link);
                }
 
                protected virtual void OnCbxFilterItemChanged (object sender, System.EventArgs e)
                {
                        ArrayList listecritere = new ArrayList();
                        (cbxFilterValue.Model as ListStore).Clear();
                        switch (cbxFilterItem.Active)
                        {
                        case 0 :
                                //Filtrage par auteur
                                listecritere = mybase.GetAuthorList();
                                break;
                        case 1 : 
                                //Filtrage par genre 
                                listecritere = mybase.GetGenreList();
                                break;
                        case 2 :
                                //Filtrage par note
                                for (int i=0;i<=5;i++)
                                        listecritere.Add(i.ToString());
                                break;
                        case 3 :
                                listecritere.Add(Catalog.GetString("Oui"));
                                listecritere.Add(Catalog.GetString("Non"));
                                break;
                        }
                        foreach (string critere in listecritere)
                                cbxFilterValue.AppendText(critere);
                }
 
                protected virtual void OnCbxFilterValueChanged (object sender, System.EventArgs e)
                {
                        ArrayList listid = new ArrayList();
                        (trvBooklist.Model as ListStore).Clear();
                        string searchvalue="";
                        if (cbxFilterItem.Active==3)
                        {
                                if (cbxFilterValue.Active==0) searchvalue="O";
                                if (cbxFilterValue.Active==1) searchvalue="N";
                        }
                        else
                                searchvalue=cbxFilterValue.ActiveText;
                        biblix.booksearchcriteria searchon=biblix.booksearchcriteria.author;
                        switch (cbxFilterItem.Active)
                        {
                        case 0 :
                                //Filtrage par auteur
                                searchon = biblix.booksearchcriteria.author ;
                                break;
                        case 1 : 
                                //Filtrage par genre 
                                searchon = biblix.booksearchcriteria.genre;
                                break;
                        case 2 :
                                //Filtrage par note
                                searchon = biblix.booksearchcriteria.note;
                                break;
                        case 3 :
                                searchon = biblix.booksearchcriteria.read;
                                break;
                        }
                        listid = mybase.SearchBook(searchon,searchvalue);
                        foreach(string id in listid)
                        {
                                book thisbook = mybase.getbook(id); 
                                (trvBooklist.Model as ListStore).AppendValues(thisbook);
                        }
                }
        }
}