Class: DownloadedWin
Overview
Constant Summary collapse
- GemDirs =
%x{ gem environment gempath }.split(/:/).map! do |dir| File.join(dir.strip, 'cache') end
- GroupName =
"DownloadedGemWindow"
Instance Attribute Summary collapse
-
#gemViewer ⇒ Object
Returns the value of attribute gemViewer.
Instance Method Summary collapse
- #allFilesInDir(dir) ⇒ Object
- #createWidget ⇒ Object
- #delete ⇒ Object
-
#initialize(parent = nil) ⇒ DownloadedWin
constructor
A new instance of DownloadedWin.
- #install ⇒ Object
- #itemClicked(item) ⇒ Object
- #notifyDownload ⇒ Object
- #notifyInstall ⇒ Object
- #readSettings ⇒ Object
- #unpack ⇒ Object
- #updateList ⇒ Object
- #writeSettings ⇒ Object
Constructor Details
#initialize(parent = nil) ⇒ DownloadedWin
Returns a new instance of DownloadedWin.
105 106 107 108 109 110 111 112 |
# File 'lib/downloadedwin.rb', line 105 def initialize(parent=nil) super(parent) createWidget readSettings Qt::Timer.singleShot(0, self, SLOT(:updateList)) end |
Instance Attribute Details
#gemViewer ⇒ Object
Returns the value of attribute gemViewer.
192 193 194 |
# File 'lib/downloadedwin.rb', line 192 def gemViewer @gemViewer end |
Instance Method Details
#allFilesInDir(dir) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/downloadedwin.rb', line 158 def allFilesInDir(dir) return [] unless dir exDir = File.(dir) return [] unless File.directory?(exDir) Dir.chdir(exDir) files = Dir['*.gem'] gems = files.map do |f| fGem = FetchedGem.new fGem.fileName = f fGem.directory = exDir fGem.installed = InstalledGemList.checkVersionedGemInstalled(f) fGem end end |
#createWidget ⇒ Object
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 |
# File 'lib/downloadedwin.rb', line 118 def createWidget @gemFileList = DownloadedTable.new @filterLine = KDE::LineEdit.new do |w| connect(w,SIGNAL('textChanged(const QString &)'), @gemFileList, SLOT('filterChanged(const QString &)')) w.setClearButtonShown(true) end @installBtn = KDE::PushButton.new(KDE::Icon.new('run-build-install'), 'Install') @deleteBtn = KDE::PushButton.new(KDE::Icon.new('edit-delete'), 'Delete') @unpackBtn = KDE::PushButton.new('Unpack') # connect(@gemFileList, SIGNAL('itemClicked(QTableWidgetItem *)'), self, SLOT('itemClicked(QTableWidgetItem *)')) connect(@installBtn, SIGNAL(:clicked), self, SLOT(:install)) connect(@deleteBtn, SIGNAL(:clicked), self, SLOT(:delete)) connect(@unpackBtn, SIGNAL(:clicked), self, SLOT(:unpack)) # layout lo = Qt::VBoxLayout.new lo.addWidgets('Filter:', @filterLine) lo.addWidget(@gemFileList) lo.addWidgets(nil, @installBtn, @unpackBtn, @deleteBtn) setLayout(lo) end |
#delete ⇒ Object
226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/downloadedwin.rb', line 226 def delete fetchedGem = @gemFileList.currentGem return unless fetchedGem and !(GemDirs.include?(fetchedGem.directory) \ and fetchedGem.installed) filePath = fetchedGem.filePath if File.writable?(filePath) then File.unlink(filePath) passiveMessage(i18n('Deleted ') + filePath) updateList end end |
#install ⇒ Object
215 216 217 218 219 220 221 222 223 |
# File 'lib/downloadedwin.rb', line 215 def install fetchedGem = @gemFileList.currentGem return unless fetchedGem and !fetchedGem.installed filePath = fetchedGem.filePath gem = GemItem::getGemfromPath(filePath) gem.addLocalPath(filePath) @gemViewer.install(gem, true) # localFlag = true end |
#itemClicked(item) ⇒ Object
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/downloadedwin.rb', line 194 def itemClicked(item) fetchedGem = @gemFileList.gem(item) return unless fetchedGem filePath = fetchedGem.filePath return unless File.exist?(filePath) @installBtn.enabled = @deleteBtn.enabled = ! fetchedGem.installed files = %x{ tar xf #{filePath} data.tar.gz -O | gunzip -c | tar t }.split(/\n/) files.unshift @gemViewer.setFiles(files) gem = GemItem::getGemfromCache(filePath) @gemViewer.setDetail(gem) proc = lambda do |item| file = item.text @gemViewer.previewWin.setText( file, %x{ tar xf #{filePath.shellescape} data.tar.gz -O | gunzip -c | tar x #{file.shellescape} -O } ) end @gemViewer.setPreviewProc(proc) end |
#notifyDownload ⇒ Object
184 185 186 |
# File 'lib/downloadedwin.rb', line 184 def notifyDownload updateList end |
#notifyInstall ⇒ Object
188 189 190 |
# File 'lib/downloadedwin.rb', line 188 def notifyInstall updateList end |
#readSettings ⇒ Object
150 151 152 153 |
# File 'lib/downloadedwin.rb', line 150 def readSettings config = $config.group(GroupName) @gemFileList.horizontalHeader.restoreState(config.readEntry('Header', @gemFileList.horizontalHeader.saveState)) end |
#unpack ⇒ Object
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/downloadedwin.rb', line 240 def unpack fetchedGem = @gemFileList.currentGem filePath = fetchedGem.filePath if Settings.autoUnpackFlag then dir = Settings.autoUnpackDir else dir = Qt::FileDialog::getExistingDirectory(nil, 'select folder', Settings.autoUnpackDir) return unless dir Settings.autoUnpackDir.setUrl(dir) end outDir = File.join(dir, File.basename(filePath).sub(File.extname(filePath),'')) FileUtils.remove_dir(outDir, true) FileUtils.mkdir_p(outDir) %x{ tar xf #{filePath.shellescape} data.tar.gz -O | gunzip -c | tar x --directory=#{outDir.shellescape} } end |
#updateList ⇒ Object
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 |
# File 'lib/downloadedwin.rb', line 157 def updateList def allFilesInDir(dir) return [] unless dir exDir = File.(dir) return [] unless File.directory?(exDir) Dir.chdir(exDir) files = Dir['*.gem'] gems = files.map do |f| fGem = FetchedGem.new fGem.fileName = f fGem.directory = exDir fGem.installed = InstalledGemList.checkVersionedGemInstalled(f) fGem end end dirs = GemDirs + [ Settings.autoFetchDir ] gems = dirs.uniq.inject([]) do |res, dir| res + allFilesInDir(dir) end # @gemFileList.updateGemList(gems) @filterLine.text = '' end |