[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kubeplayer] lib: simplify signal and slots related to video play back
From: Robert Riemann <robert.riemann () physik ! hu-berlin ! de>
Date: 2011-11-25 0:32:12
Message-ID: 20111125003212.EA523A60C6 () git ! kde ! org
[Download RAW message or body]
Git commit 6d957e4c872e4b7e94b6583818c716e8b5c2d8a5 by Robert Riemann.
Committed on 25/11/2011 at 00:52.
Pushed by rriemann into branch 'master'.
simplify signal and slots related to video play back
M +9 -23 lib/List.rb
M +55 -20 lib/MainWindow.rb
M +4 -2 lib/Video.rb
M +4 -3 lib/provider/youtube/Youtube.rb
http://commits.kde.org/kubeplayer/6d957e4c872e4b7e94b6583818c716e8b5c2d8a5
diff --git a/lib/List.rb b/lib/List.rb
index d6b48ba..c4b013a 100644
--- a/lib/List.rb
+++ b/lib/List.rb
@@ -7,17 +7,18 @@ module KubePlayer
class VideoList < Qt::AbstractListModel
slots :update_thumbnail
- signals 'active_row_changed(int)'
signals 'play_this(QVariant)'
+ slots 'request_play(QVariant)'
attr_reader :videos
attr_accessor :queryVeto
- def initialize providerClass, minimumSize = 0
+ def initialize providerClass, mainWindow, minimumSize = 0
super()
@videos = []
@provider = providerClass
@minimumSize = minimumSize
+ @mainWindow = mainWindow
@activeVideo = nil
@activeRow = nil
@autostart = false
@@ -34,7 +35,7 @@ class VideoList < Qt::AbstractListModel
when VideoRole then
return Qt::Variant.from_value video
when ActiveTrackRole then
- return Qt::Variant.new(video == @activeVideo)
+ return Qt::Variant.new(row == @activeRow)
when Qt::DisplayRole, Qt::StatusTipRole then
return Qt::Variant.new video.to_s
end
@@ -80,7 +81,7 @@ class VideoList < Qt::AbstractListModel
@activeVideo = @videos[row]
emit dataChanged(create_index(row, 0), create_index(row, column_count()-1))
- emit active_row_changed(row)
+ @mainWindow.activeVideo = @activeVideo
else
@activeRow = nil
@activeVideo = nil
@@ -100,9 +101,7 @@ class VideoList < Qt::AbstractListModel
def push video
connect video, SIGNAL(:got_thumbnail), self, SLOT(:update_thumbnail)
- connect(video, SIGNAL('got_video_url(QVariant)')) do |variant|
- emit play_this(variant)
- end
+ connect video, SIGNAL(:got_video_url), @mainWindow, SLOT(:request_play)
begin_insert_rows Qt::ModelIndex.new, @videos.size, @videos.size
@videos.push video
@@ -158,7 +157,7 @@ class ListView < Qt::ListView
attr_accessor :videoList
- def initialize parent, providerClass, videoPlayer, searchWidget, listDock
+ def initialize parent, providerClass, mainWindow, searchWidget, listDock
super(parent)
# self.view_mode = Qt::ListView::ListMode
self.item_delegate = VideoItemDelegate.new(self)
@@ -170,11 +169,11 @@ class ListView < Qt::ListView
self.uniform_item_sizes = true
@provider = providerClass
- @videoPlayer = videoPlayer
+ @mainWindow = mainWindow
@searchWidget = searchWidget
@listDock = listDock
- @videoList = VideoList.new @provider
+ @videoList = VideoList.new @provider, @mainWindow
self.model = @videoList
connect(self, SIGNAL('activated(QModelIndex)')) do |modelIndex|
@@ -188,19 +187,6 @@ class ListView < Qt::ListView
end
end
- connect(@videoList, SIGNAL('active_row_changed(int)')) do |row|
- video = @videoList[row]
- @active_video = video
- video.request_video_url
- end
-
- connect(@videoList, SIGNAL('play_this(QVariant)')) do |variant|
- video = variant.value
- if @active_video == video
- @videoPlayer.play Phonon::MediaSource.new video.video_url
- end
- end
-
@searchWidget.connect( SIGNAL :returnPressed ) do
@videoList.query @searchWidget.line_edit.text
@searchWidget.line_edit.clear
diff --git a/lib/MainWindow.rb b/lib/MainWindow.rb
index 47b8478..e0eaa4c 100644
--- a/lib/MainWindow.rb
+++ b/lib/MainWindow.rb
@@ -13,7 +13,9 @@ end
class MainWindow < KDE::MainWindow
- slots 'toogleVolumeSlider(bool)', 'stateChanged(Phonon::State, Phonon::State)', \
'handle_video_request(KUrl)' + slots 'toogleVolumeSlider(bool)', \
'stateChanged(Phonon::State, Phonon::State)', 'handle_video_request(KUrl)', \
'request_play()' +
+ attr_reader :activeVideo
def stateChanged state, stateBefore
case state
@@ -31,6 +33,11 @@ class MainWindow < KDE::MainWindow
end
end
+ def activeVideo= video
+ @activeVideo = video
+ video.request_video_url
+ end
+
def ini_phonon collection, menu, controlBar
@videoPlayer = Phonon::VideoPlayer.new Phonon::VideoCategory, self
@videoPlayer.media_object.tick_interval = 100
@@ -109,10 +116,29 @@ class MainWindow < KDE::MainWindow
action = collection.add_action 'download', KDE::Action.new( KDE::Icon.new( \
'download' ), i18n( 'Download' ), self ) action.connect( SIGNAL( :triggered ) ) do
- if @video
- STDERR.puts @video.filename
- saveTo = KDE::FileDialog::getSaveUrl(KDE::Url.new, \
"*.#{@video.fileextension.to_s}")
- KIO::file_copy(@video.video_url, saveTo)
+ if @activeVideo
+ # saveTo = KDE::FileDialog::getSaveUrl(KDE::Url.new, \
"*.#{@activeVideo.fileextension.to_s}") +
+ unless KDE::StandardDirs::findExe('kget').nil?
+ unless Qt::DBusConnection::sessionBus().interface().isServiceRegistered("org.kde.kget").value \
# QDBusReply<bool>, bool via reply.value + \
KDE::ToolInvocation::kdeinitExecWait("kget") + end
+ kget = Qt::DBusInterface.new("org.kde.kget", "/KGet", "org.kde.kget.main")
+ if kget.isValid
+ # transfer = kget.call("addTransfer", \
@activeVideo.video_url.prettyUrl(), @activeVideo.filename, false); + \
transfer = kget.call("showNewTransferDialog", [@activeVideo.video_url.prettyUrl, '~/' \
+ @activeVideo.filename]) + # kget.call("showNewTransferDialog", \
[@activeVideo.video_url.prettyUrl]) # FIXME just takes playpack as filename + \
end + end
+ # KIO::file_copy(@video.video_url, saveTo)
+ end
+ end
+ controlBar.add_action action
+
+ action = collection.add_action 'open-browser', KDE::Action.new( KDE::Icon.new( \
'applications-internet' ), i18n( 'Open in Browser' ), self ) + action.connect( \
SIGNAL( :triggered ) ) do + if @activeVideo
+ Qt::DesktopServices::openUrl @activeVideo.url
end
end
controlBar.add_action action
@@ -179,27 +205,36 @@ class MainWindow < KDE::MainWindow
@searchWidget.set_size_policy(Qt::SizePolicy::Fixed, Qt::SizePolicy::Fixed)
controlBar.add_widget @searchWidget
- @listWidget = ListView.new @listDock, Youtube::Video, @videoPlayer, \
@searchWidget, @listDock + @listWidget = ListView.new @listDock, Youtube::Video, \
self, @searchWidget, @listDock @listDock.widget = @listWidget
self.show
end
+ def request_play
+ video = sender()
+ if video == @activeVideo
+ play_video video
+ end
+ end
+
+ def play_video video
+ @videoPlayer.play Phonon::MediaSource.new video.video_url
+ @resolutionLabel.text = "#{video.resolution}p"
+ end
+
def handle_video_request kurl
- video = Video::get_type kurl
- if video
- connect(video, SIGNAL('got_video_url(QVariant)')) do |variant|
- @video = variant.value
- @videoPlayer.play Phonon::MediaSource.new @video.video_url
- @resolutionLabel.text = "#{@video.resolution}p"
- end
- video.request_video_url
- @listDock.hide
- else
- msg = KDE::i18n "The given URL <a href='%1'>%1</a> is not supported, because \
there is appropriate website plugin.<br />You may want to file a feature request.", \
kurl.url
- STDERR.puts msg
- KDE::MessageBox.messageBox nil, KDE::MessageBox::Sorry, msg, i18n("No \
supported URL")
- end
+ video = Video::get_type kurl
+ if video
+ @listDock.hide
+ self.activeVideo = video
+ connect(video, SIGNAL('got_video_url()'), self, SLOT('request_play()'))
+ video.request_video_url
+ else
+ msg = KDE::i18n "The given URL <a href='%1'>%1</a> is not supported, because \
there is appropriate website plugin.<br />You may want to file a feature request.", \
kurl.url + STDERR.puts msg
+ KDE::MessageBox.messageBox nil, KDE::MessageBox::Sorry, msg, i18n("No \
supported URL") + end
end
end
diff --git a/lib/Video.rb b/lib/Video.rb
index ac7e244..4a5e374 100644
--- a/lib/Video.rb
+++ b/lib/Video.rb
@@ -58,7 +58,7 @@ class Video < Qt::Object
attr_accessor :title
- signals :got_thumbnail, 'got_video_url(QVariant)'
+ signals :got_thumbnail, 'got_video_url()'
#:call-seq:
# thumbnail_url() => KDE::Url
@@ -136,9 +136,11 @@ class Video < Qt::Object
@fileextension = nil
end
+=begin
def to_s
- @title or '[unbenannt]'
+ "<#{@title or '[unbenannt]'}>"
end
+=end
# FIXME (this implementation doesn't work to protect the constructor
protected :initialize
diff --git a/lib/provider/youtube/Youtube.rb b/lib/provider/youtube/Youtube.rb
index 8cc0a3d..6a35f6a 100644
--- a/lib/provider/youtube/Youtube.rb
+++ b/lib/provider/youtube/Youtube.rb
@@ -101,10 +101,11 @@ class Video < KubePlayer::Video
# STDERR.puts fmtUrlMap_by_Resolution.inspect
@resolution, video = fmtUrlMap_by_Resolution.max
@fileextension = NUMBER2FORMAT[video[0]]
- @filename = "#{metaInfo[:title].gsub('+','_')}.#{@fileextension}"
+ # @filename = "#{metaInfo[:title].gsub('+',' ')}.#{@fileextension}"
+ @filename = \
"#{KDE::Url::fromPercentEncoding(Qt::ByteArray.new(metaInfo[:title])).gsub('+',' \
')}.#{@fileextension}" # STDERR.puts "#{resolution}p, #{@filename}"
@video_url = KDE::Url.new video[1]
- emit got_video_url(Qt::Variant.from_value(self))
+ emit got_video_url
else
if @el_mode_index < EL_MODE.size - 1
@el_mode_index += 1
@@ -122,7 +123,7 @@ class Video < KubePlayer::Video
end
end
elsif @video_url != false
- emit got_video_url(Qt::Variant.from_value(self))
+ emit got_video_url
end
end
end
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic