Class: GemSourceDlg
Constant Summary collapse
- UrlRegexp =
URI.regexp(['http', 'https'])
- GithubUrl =
'http://gems.github.com'
- RubygemsUrl =
'http://rubygems.org/'
- SystemUrls =
[ GithubUrl, RubygemsUrl ]
Instance Method Summary collapse
-
#accept ⇒ Object
overwrite virtual method.
- #addItem ⇒ Object
- #addUrl(url) ⇒ Object
- #createWidget ⇒ Object
- #deleteItem ⇒ Object
- #deleteUrl(url) ⇒ Object
-
#exec ⇒ Object
—————–.
- #githubStateChanged(state) ⇒ Object
-
#initialize(parent = nil) ⇒ GemSourceDlg
constructor
A new instance of GemSourceDlg.
- #rubygemsStateChanged(state) ⇒ Object
- #updateSources ⇒ Object
Constructor Details
#initialize(parent = nil) ⇒ GemSourceDlg
Returns a new instance of GemSourceDlg.
4 5 6 7 8 |
# File 'lib/gemsource.rb', line 4 def initialize(parent=nil) super(parent) self.windowTitle = i18n('Gem sources') createWidget end |
Instance Method Details
#accept ⇒ Object
overwrite virtual method
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/gemsource.rb', line 137 def accept msg = "" newUrls = Set.new(@sourceUrls.keys) deletes = @orgUrls - newUrls deletes.each do |url| msg += "delete #{url}\n" %x{ gem sources --remove #{url} } end adds = newUrls - @orgUrls adds.each do |url| msg += "add #{url}\n" %x{ gem sources --add #{url} } end unless msg.empty? then KDE::MessageBox.information(self, msg) end super end |
#addItem ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/gemsource.rb', line 84 def addItem url = @addUrlLineEdit.text.strip case url when RubygemsUrl @rubygemsCheckBox.checked = true when GithubUrl @githubCheckBox.checked = true else unless url.empty? or @sourceUrls.has_key?(url) then addUrl(url) end end end |
#addUrl(url) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/gemsource.rb', line 67 def addUrl(url) unless @sourceUrls[url] then @sourceUrls[url] = item = Qt::ListWidgetItem.new(url) @sourceList.addItem(item) end end |
#createWidget ⇒ Object
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 |
# File 'lib/gemsource.rb', line 10 def createWidget @sourceList = Qt::ListWidget.new @rubygemsCheckBox = Qt::CheckBox.new(i18n('add rubygems source')) connect(@rubygemsCheckBox, SIGNAL('stateChanged(int)'), self, \ SLOT('rubygemsStateChanged(int)')) @githubCheckBox = Qt::CheckBox.new(i18n('add github source')) connect(@githubCheckBox, SIGNAL('stateChanged(int)'), self, \ SLOT('githubStateChanged(int)')) @addUrlLineEdit = KDE::LineEdit.new @addBtn = KDE::PushButton.new(i18n('add')) @deleteBtn = KDE::PushButton.new(i18n('delete')) @okBtn = KDE::PushButton.new(KDE::Icon.new('dialog-ok'), i18n('Ok')) @cancelBtn = KDE::PushButton.new(KDE::Icon.new('dialog-cancel'), i18n('Cancel')) connect(@addBtn, SIGNAL(:clicked), self, SLOT(:addItem)) connect(@deleteBtn, SIGNAL(:clicked), self, SLOT(:deleteItem)) connect(@okBtn, SIGNAL(:clicked), self, SLOT(:accept)) connect(@cancelBtn, SIGNAL(:clicked), self, SLOT(:reject)) # layout lo = Qt::VBoxLayout.new do |l| l.addWidget(@sourceList) l.addWidget(@rubygemsCheckBox) l.addWidget(@githubCheckBox) l.addWidgets(@deleteBtn, nil) l.addWidgets(@addBtn, @addUrlLineEdit) l.addWidgets(nil, @okBtn, @cancelBtn) l.addStretch end setLayout(lo) end |
#deleteItem ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/gemsource.rb', line 99 def deleteItem row = @sourceList.currentRow return unless row >= 0 case @sourceList.item(row).text when RubygemsUrl @rubygemsCheckBox.checked = false when GithubUrl @githubCheckBox.checked = false else @sourceList.takeItem(row) end end |
#deleteUrl(url) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/gemsource.rb', line 74 def deleteUrl(url) if @sourceUrls[url] then row = @sourceList.row(@sourceUrls[url]) @sourceList.takeItem(row) # @sourceList.removeItemWidget(@sourceUrls[url]) # cannot use ? @sourceUrls.delete(url) end end |
#githubStateChanged(state) ⇒ Object
119 120 121 122 123 124 125 |
# File 'lib/gemsource.rb', line 119 def githubStateChanged(state) if state == Qt::Checked then addUrl(GithubUrl) else deleteUrl(GithubUrl) end end |
#rubygemsStateChanged(state) ⇒ Object
128 129 130 131 132 133 134 |
# File 'lib/gemsource.rb', line 128 def rubygemsStateChanged(state) if state == Qt::Checked then addUrl(RubygemsUrl) else deleteUrl(RubygemsUrl) end end |
#updateSources ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/gemsource.rb', line 45 def updateSources @sourceList.clear @sourceUrls = {} @rubygemsCheckBox.checked = false @githubCheckBox.checked = false %x{ gem sources -l }.split(/\n/).each do |line| url = line[UrlRegexp] if url then case url when RubygemsUrl @rubygemsCheckBox.checked = true when GithubUrl @githubCheckBox.checked = true else @sourceUrls[url] = item = Qt::ListWidgetItem.new(url) @sourceList.addItem(item) end end end @orgUrls = Set.new(@sourceUrls.keys) end |