/EditTagDialog.rb
Ruby | 140 lines | 109 code | 15 blank | 16 comment | 4 complexity | 6a426f21856c2a179bf500199b61ec4c MD5 | raw file
Possible License(s): GPL-2.0
- # Edit tags dialog
- # Copyright (C) <2008-2010> Abdelrahman ghanem <abom.jdev@gmail.com>
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 2 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- # You should have received a copy of the GNU General Public License along
- # with this program; if not, write to the Free Software Foundation, Inc.,
- # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- require 'UiEditTagDialog'
- class EditTagDialog < Qt::Dialog
- attr :file,true
- attr :apply_for_all
- attr :sura
- attr :shiekh
- attr :mushaf
- attr :year
- attr :comment
- attr :cover_image
- attr :cover_image_desc
- attr :mimetype
-
- slots 'save()','en_title_field(int)','browse()','save_image()'
-
- def initialize parent=nil
- super parent
- @parent=parent
- @edialog=Ui_EditTagDialog.new
- @edialog.setupUi self
-
- @tagger=Tagger.new
-
- connect(@edialog.btnsave,SIGNAL('clicked()'),
- self,SLOT('save()'))
- connect(@edialog.btnbrowse,SIGNAL('clicked()'),
- self,SLOT('browse()'))
- connect(@edialog.btnsaveas,SIGNAL('clicked()'),
- self,SLOT('save_image()'))
- connect(@edialog.checkall,SIGNAL('stateChanged(int)'),
- self,SLOT('en_title_field(int)'))
-
- end
-
- def clear
- @edialog.txtsura.clear
- @edialog.txtshiekh.clear
- @edialog.txtmushaf.clear
- @edialog.txtyear.clear
- @edialog.ptxtcomment.clear
- @edialog.checkall.checked=false
- end
-
- def fill_fields!
- @edialog.txtfile.text=file
- @tagger.file=file
- @tagger.get!
- @edialog.txtsura.text=@tagger.title
- @edialog.txtshiekh.text=@tagger.artist
- @edialog.txtmushaf.text=@tagger.album
- @edialog.txtyear.text=@tagger.year
- @edialog.ptxtcomment.plainText=@tagger.comment
- if File.extname(file).downcase != ".mp3"
- @edialog.gbcover.hide
- self.resize(400,300)
- elsif !@tagger.cover_image.nil?
- ext=@tagger.mimetype.split('/')[1]
- temp_file="/tmp/temporary_image_for_preview.#{ext}"
- File.open(temp_file,'wb+'){|f|f.write(@tagger.cover_image)}
- @edialog.txtcoverimage.text=temp_file
- image=Qt::Pixmap.new(temp_file)
- #image.loadFromData(Qt::ByteArray.new(@tagger.cover_image))
- @edialog.lblpreview.pixmap=image
- @edialog.btnsave.enabled=true
- @edialog.txtco_img_desc.plainText=@tagger.cover_image_desc
- elsif @tagger.cover_image.nil?
- @edialog.txtcoverimage.text="Not Found"
- @edialog.btnsaveas.enabled=false
- end
- end
-
- def save
- if !@edialog.checkall.checked
- @tagger.title=@edialog.txtsura.text
- @tagger.artist=@edialog.txtshiekh.text
- @tagger.album=@edialog.txtmushaf.text
- @tagger.year=@edialog.txtyear.text
- @tagger.comment=@edialog.ptxtcomment.plainText
- @tagger.cover_image=@edialog.txtcoverimage.text
- @tagger.cover_image_desc=@edialog.txtco_img_desc.plainText
- @tagger.set!
- self.reject
- else
- @shiekh=@edialog.txtshiekh.text
- @mushaf=@edialog.txtmushaf.text
- @year=@edialog.txtyear.text
- @comment=@edialog.ptxtcomment.plainText
- @cover_image=@edialog.txtcoverimage.text
- @cover_image_desc=@edialog.txtco_img_desc.plainText
- self.accept
- end
- @apply_for_all=@edialog.checkall.checked
- end
-
- def browse
- image=Qt::FileDialog.getOpenFileName(self, tr("Choose Image File"),
- ENV['HOME'],
- tr("Images (*.jpeg *.jpg *png)"))
- unless image.nil?
- @mimetype="image/#{File.extname(image)[1..-1]}"
- @edialog.txtcoverimage.text=image
- @edialog.lblpreview.pixmap=Qt::Pixmap.new(image)
- end
- end
-
- def en_title_field int
- case int
- when 0 : @edialog.txtsura.enabled=true
- when 2 : @edialog.txtsura.enabled=false
- end
- end
-
- def save_image
- out_image=Qt::FileDialog.getSaveFileName(self, tr("Output Image File"),
- ENV['HOME'],
- tr("Images (*.jpeg *.jpg *png)"))
- if out_image
- @edialog.lblpreview.pixmap.save(out_image)
- end
- end
-
- end