PageRenderTime 11ms CodeModel.GetById 5ms RepoModel.GetById 0ms app.codeStats 0ms

/EditTagDialog.rb

https://bitbucket.org/abom/qurename
Ruby | 140 lines | 109 code | 15 blank | 16 comment | 4 complexity | 6a426f21856c2a179bf500199b61ec4c MD5 | raw file
Possible License(s): GPL-2.0
  1. # Edit tags dialog
  2. # Copyright (C) <2008-2010> Abdelrahman ghanem <abom.jdev@gmail.com>
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. # You should have received a copy of the GNU General Public License along
  14. # with this program; if not, write to the Free Software Foundation, Inc.,
  15. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  16. require 'UiEditTagDialog'
  17. class EditTagDialog < Qt::Dialog
  18. attr :file,true
  19. attr :apply_for_all
  20. attr :sura
  21. attr :shiekh
  22. attr :mushaf
  23. attr :year
  24. attr :comment
  25. attr :cover_image
  26. attr :cover_image_desc
  27. attr :mimetype
  28. slots 'save()','en_title_field(int)','browse()','save_image()'
  29. def initialize parent=nil
  30. super parent
  31. @parent=parent
  32. @edialog=Ui_EditTagDialog.new
  33. @edialog.setupUi self
  34. @tagger=Tagger.new
  35. connect(@edialog.btnsave,SIGNAL('clicked()'),
  36. self,SLOT('save()'))
  37. connect(@edialog.btnbrowse,SIGNAL('clicked()'),
  38. self,SLOT('browse()'))
  39. connect(@edialog.btnsaveas,SIGNAL('clicked()'),
  40. self,SLOT('save_image()'))
  41. connect(@edialog.checkall,SIGNAL('stateChanged(int)'),
  42. self,SLOT('en_title_field(int)'))
  43. end
  44. def clear
  45. @edialog.txtsura.clear
  46. @edialog.txtshiekh.clear
  47. @edialog.txtmushaf.clear
  48. @edialog.txtyear.clear
  49. @edialog.ptxtcomment.clear
  50. @edialog.checkall.checked=false
  51. end
  52. def fill_fields!
  53. @edialog.txtfile.text=file
  54. @tagger.file=file
  55. @tagger.get!
  56. @edialog.txtsura.text=@tagger.title
  57. @edialog.txtshiekh.text=@tagger.artist
  58. @edialog.txtmushaf.text=@tagger.album
  59. @edialog.txtyear.text=@tagger.year
  60. @edialog.ptxtcomment.plainText=@tagger.comment
  61. if File.extname(file).downcase != ".mp3"
  62. @edialog.gbcover.hide
  63. self.resize(400,300)
  64. elsif !@tagger.cover_image.nil?
  65. ext=@tagger.mimetype.split('/')[1]
  66. temp_file="/tmp/temporary_image_for_preview.#{ext}"
  67. File.open(temp_file,'wb+'){|f|f.write(@tagger.cover_image)}
  68. @edialog.txtcoverimage.text=temp_file
  69. image=Qt::Pixmap.new(temp_file)
  70. #image.loadFromData(Qt::ByteArray.new(@tagger.cover_image))
  71. @edialog.lblpreview.pixmap=image
  72. @edialog.btnsave.enabled=true
  73. @edialog.txtco_img_desc.plainText=@tagger.cover_image_desc
  74. elsif @tagger.cover_image.nil?
  75. @edialog.txtcoverimage.text="Not Found"
  76. @edialog.btnsaveas.enabled=false
  77. end
  78. end
  79. def save
  80. if !@edialog.checkall.checked
  81. @tagger.title=@edialog.txtsura.text
  82. @tagger.artist=@edialog.txtshiekh.text
  83. @tagger.album=@edialog.txtmushaf.text
  84. @tagger.year=@edialog.txtyear.text
  85. @tagger.comment=@edialog.ptxtcomment.plainText
  86. @tagger.cover_image=@edialog.txtcoverimage.text
  87. @tagger.cover_image_desc=@edialog.txtco_img_desc.plainText
  88. @tagger.set!
  89. self.reject
  90. else
  91. @shiekh=@edialog.txtshiekh.text
  92. @mushaf=@edialog.txtmushaf.text
  93. @year=@edialog.txtyear.text
  94. @comment=@edialog.ptxtcomment.plainText
  95. @cover_image=@edialog.txtcoverimage.text
  96. @cover_image_desc=@edialog.txtco_img_desc.plainText
  97. self.accept
  98. end
  99. @apply_for_all=@edialog.checkall.checked
  100. end
  101. def browse
  102. image=Qt::FileDialog.getOpenFileName(self, tr("Choose Image File"),
  103. ENV['HOME'],
  104. tr("Images (*.jpeg *.jpg *png)"))
  105. unless image.nil?
  106. @mimetype="image/#{File.extname(image)[1..-1]}"
  107. @edialog.txtcoverimage.text=image
  108. @edialog.lblpreview.pixmap=Qt::Pixmap.new(image)
  109. end
  110. end
  111. def en_title_field int
  112. case int
  113. when 0 : @edialog.txtsura.enabled=true
  114. when 2 : @edialog.txtsura.enabled=false
  115. end
  116. end
  117. def save_image
  118. out_image=Qt::FileDialog.getSaveFileName(self, tr("Output Image File"),
  119. ENV['HOME'],
  120. tr("Images (*.jpeg *.jpg *png)"))
  121. if out_image
  122. @edialog.lblpreview.pixmap.save(out_image)
  123. end
  124. end
  125. end