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 =3D 0 + def initialize providerClass, mainWindow, minimumSize =3D 0 super() @videos =3D [] @provider =3D providerClass @minimumSize =3D minimumSize + @mainWindow =3D mainWindow @activeVideo =3D nil @activeRow =3D nil @autostart =3D 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 =3D=3D @activeVideo) + return Qt::Variant.new(row =3D=3D @activeRow) when Qt::DisplayRole, Qt::StatusTipRole then return Qt::Variant.new video.to_s end @@ -80,7 +81,7 @@ class VideoList < Qt::AbstractListModel @activeVideo =3D @videos[row] = emit dataChanged(create_index(row, 0), create_index(row, column_coun= t()-1)) - emit active_row_changed(row) + @mainWindow.activeVideo =3D @activeVideo else @activeRow =3D nil @activeVideo =3D 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 =3D Qt::ListView::ListMode self.item_delegate =3D VideoItemDelegate.new(self) @@ -170,11 +169,11 @@ class ListView < Qt::ListView self.uniform_item_sizes =3D true = @provider =3D providerClass - @videoPlayer =3D videoPlayer + @mainWindow =3D mainWindow @searchWidget =3D searchWidget @listDock =3D listDock = - @videoList =3D VideoList.new @provider + @videoList =3D VideoList.new @provider, @mainWindow self.model =3D @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 =3D @videoList[row] - @active_video =3D video - video.request_video_url - end - - connect(@videoList, SIGNAL('play_this(QVariant)')) do |variant| - video =3D variant.value - if @active_video =3D=3D 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::S= tate)', 'handle_video_request(KUrl)' + slots 'toogleVolumeSlider(bool)', 'stateChanged(Phonon::State, Phonon::S= tate)', '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=3D video + @activeVideo =3D video + video.request_video_url + end = + def ini_phonon collection, menu, controlBar @videoPlayer =3D Phonon::VideoPlayer.new Phonon::VideoCategory, self @videoPlayer.media_object.tick_interval =3D 100 @@ -109,10 +116,29 @@ class MainWindow < KDE::MainWindow = action =3D collection.add_action 'download', KDE::Action.new( KDE::Ico= n.new( 'download' ), i18n( 'Download' ), self ) action.connect( SIGNAL( :triggered ) ) do - if @video - STDERR.puts @video.filename - saveTo =3D KDE::FileDialog::getSaveUrl(KDE::Url.new, "*.#{@video.f= ileextension.to_s}") - KIO::file_copy(@video.video_url, saveTo) + if @activeVideo + # saveTo =3D KDE::FileDialog::getSaveUrl(KDE::Url.new, "*.#{@activ= eVideo.fileextension.to_s}") + + unless KDE::StandardDirs::findExe('kget').nil? + unless Qt::DBusConnection::sessionBus().interface().isServiceReg= istered("org.kde.kget").value # QDBusReply, bool via reply.value + KDE::ToolInvocation::kdeinitExecWait("kget") + end + kget =3D Qt::DBusInterface.new("org.kde.kget", "/KGet", "org.kde= .kget.main") + if kget.isValid + # transfer =3D kget.call("addTransfer", @activeVideo.video_url= .prettyUrl(), @activeVideo.filename, false); + transfer =3D kget.call("showNewTransferDialog", [@activeVideo.= video_url.prettyUrl, '~/' + @activeVideo.filename]) + # kget.call("showNewTransferDialog", [@activeVideo.video_url.p= rettyUrl]) # FIXME just takes playpack as filename + end + end + # KIO::file_copy(@video.video_url, saveTo) + end + end + controlBar.add_action action + + action =3D 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::F= ixed) controlBar.add_widget @searchWidget = - @listWidget =3D ListView.new @listDock, Youtube::Video, @videoPlayer, = @searchWidget, @listDock + @listWidget =3D ListView.new @listDock, Youtube::Video, self, @searchW= idget, @listDock @listDock.widget =3D @listWidget = self.show end = + def request_play + video =3D sender() + if video =3D=3D @activeVideo + play_video video + end + end + + def play_video video + @videoPlayer.play Phonon::MediaSource.new video.video_url + @resolutionLabel.text =3D "#{video.resolution}p" + end + def handle_video_request kurl - video =3D Video::get_type kurl - if video - connect(video, SIGNAL('got_video_url(QVariant)')) do |variant| - @video =3D variant.value - @videoPlayer.play Phonon::MediaSource.new @video.video_url - @resolutionLabel.text =3D "#{@video.resolution}p" - end - video.request_video_url - @listDock.hide - else - msg =3D KDE::i18n "The given URL %1 is not supp= orted, because there is appropriate website plugin.
You may want to fi= le a feature request.", kurl.url - STDERR.puts msg - KDE::MessageBox.messageBox nil, KDE::MessageBox::Sorry, msg, i18n(= "No supported URL") - end + video =3D Video::get_type kurl + if video + @listDock.hide + self.activeVideo =3D video + connect(video, SIGNAL('got_video_url()'), self, SLOT('request_play()= ')) + video.request_video_url + else + msg =3D KDE::i18n "The given URL %1 is not suppor= ted, because there is appropriate website plugin.
You may want to file= a feature request.", kurl.url + STDERR.puts msg + KDE::MessageBox.messageBox nil, KDE::MessageBox::Sorry, msg, i18n("N= o 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() =3D> KDE::Url @@ -136,9 +136,11 @@ class Video < Qt::Object @fileextension =3D nil end = +=3Dbegin def to_s - @title or '[unbenannt]' + "<#{@title or '[unbenannt]'}>" end +=3Dend = # 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 =3D fmtUrlMap_by_Resolution.max @fileextension =3D NUMBER2FORMAT[video[0]] - @filename =3D "#{metaInfo[:title].gsub('+','_')}.#{@fileextensio= n}" + # @filename =3D "#{metaInfo[:title].gsub('+',' ')}.#{@fileextens= ion}" + @filename =3D "#{KDE::Url::fromPercentEncoding(Qt::ByteArray.new= (metaInfo[:title])).gsub('+',' ')}.#{@fileextension}" # STDERR.puts "#{resolution}p, #{@filename}" @video_url =3D 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 +=3D 1 @@ -122,7 +123,7 @@ class Video < KubePlayer::Video end end elsif @video_url !=3D false - emit got_video_url(Qt::Variant.from_value(self)) + emit got_video_url end end end