From 88bf12376d9f32137eb6067205ca0a2db1d6fe0a Mon Sep 17 00:00:00 2001 From: Laurent Montel Date: Mon, 4 Feb 2008 12:06:13 +0000 Subject: [PATCH] Allow to define where store video. Ok'ed by Lubos svn path=/trunk/KDE/kdebase/workspace/; revision=770697 --- effects/CMakeLists.txt | 4 ++-- effects/videorecord.cpp | 34 ++++++++++++++++++++++++++++------ effects/videorecord.h | 1 + effects/videorecord_config.cpp | 21 +++++++++++++++++++++ effects/videorecord_config.h | 2 ++ 5 files changed, 54 insertions(+), 8 deletions(-) diff --git a/effects/CMakeLists.txt b/effects/CMakeLists.txt index b3607839f8..a494100db7 100644 --- a/effects/CMakeLists.txt +++ b/effects/CMakeLists.txt @@ -21,7 +21,7 @@ macro(KWIN4_ADD_EFFECT_CONFIG name) endforeach(file) kde4_add_ui_files(kwin4_effect_src ${kwin4_effect_ui}) kde4_add_plugin(kcm_kwin4_effect_${name} ${kwin4_effect_src}) - target_link_libraries(kcm_kwin4_effect_${name} kwineffects ${KDE4_KDEUI_LIBS}) + target_link_libraries(kcm_kwin4_effect_${name} kwineffects ${KDE4_KIO_LIBS} ${KDE4_KDEUI_LIBS}) install(TARGETS kcm_kwin4_effect_${name} DESTINATION ${PLUGIN_INSTALL_DIR}) endmacro(KWIN4_ADD_EFFECT_CONFIG) @@ -205,7 +205,7 @@ macro_bool_to_01( CAPTURY_FOUND HAVE_CAPTURY ) if( HAVE_CAPTURY ) KWIN4_ADD_EFFECT(videorecord videorecord.cpp) KWIN4_ADD_EFFECT_CONFIG(videorecord videorecord_config.cpp) - target_link_libraries(kwin4_effect_videorecord ${CAPTURY_LDFLAGS}) + target_link_libraries(kwin4_effect_videorecord ${KDE4_KIO_LIBS} ${CAPTURY_LDFLAGS}) install( FILES videorecord.desktop videorecord_config.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kwin ) endif( HAVE_CAPTURY ) diff --git a/effects/videorecord.cpp b/effects/videorecord.cpp index 29d2298024..df220e2006 100644 --- a/effects/videorecord.cpp +++ b/effects/videorecord.cpp @@ -21,9 +21,9 @@ along with this program. If not, see . /* This effect allows recording a video from the session. - + Requires libcaptury: - + - svn co svn://77.74.232.49/captury/trunk/capseo - you may want to remove 1.10 from AUTOMAKE_OPTIONS in Makefile.am - ./autogen.sh @@ -34,7 +34,7 @@ along with this program. If not, see . - you may want to remove 1.10 from AUTOMAKE_OPTIONS in Makefile.am - ./autogen.sh - the usual configure && make && make install procedure - + Video is saved to $HOME/kwin_video.cps, use "cpsrecode -i kwin_video.cps -o - | mplayer -" to play, use mencoder the same way to create a video. @@ -49,6 +49,9 @@ along with this program. If not, see . #include #include #include +#include +#include +#include namespace KWin { @@ -122,9 +125,13 @@ void VideoRecordEffect::startRecording() kDebug( 1212 ) << "Video recording init failed"; return; } - // TODO - if( CapturySetOutputFileName( client, QFile::encodeName(QDir::homePath()+ - "/kwin_video.cps").constData() ) != CAPTURY_SUCCESS ) + KConfigGroup conf = EffectsHandler::effectConfig("VideoRecord"); + QString videoPath =conf.readEntry( "videopath", KGlobalSettings::documentPath() ); + QString videoName(videoPath +"/kwin_video1.cps" ); + while(QFile::exists( videoName )) { + autoincFilename( videoName ); + } + if( CapturySetOutputFileName( client, QFile::encodeName( videoName ).constData() ) != CAPTURY_SUCCESS ) { kDebug( 1212 ) << "Video recording file open failed"; return; @@ -133,6 +140,21 @@ void VideoRecordEffect::startRecording() kDebug( 1212 ) << "Video recording start"; } +void VideoRecordEffect::autoincFilename(QString & name) + { + // If the name contains a number then increment it + QRegExp numSearch( "(^|[^\\d])(\\d+)" ); // we want to match as far left as possible, and when the number is at the start of the name + // Does it have a number? + int start = numSearch.lastIndexIn( name ); + if (start != -1) { + // It has a number, increment it + start = numSearch.pos( 2 ); // we are only interested in the second group + QString numAsStr = numSearch.capturedTexts()[ 2 ]; + QString number = QString::number( numAsStr.toInt() + 1 ); + number = number.rightJustified( numAsStr.length(), '0' ); + name.replace( start, number.length(), number ); + } + } void VideoRecordEffect::stopRecording() { if( client == NULL ) diff --git a/effects/videorecord.h b/effects/videorecord.h index 48339314cb..1dc6f7ab52 100644 --- a/effects/videorecord.h +++ b/effects/videorecord.h @@ -42,6 +42,7 @@ class VideoRecordEffect private: void startRecording(); void stopRecording(); + void autoincFilename(QString & url); captury_config_t config; captury_t* client; QRect area; diff --git a/effects/videorecord_config.cpp b/effects/videorecord_config.cpp index 77c13bff9d..666967de6c 100644 --- a/effects/videorecord_config.cpp +++ b/effects/videorecord_config.cpp @@ -28,8 +28,13 @@ along with this program. If not, see . #include #include #include +#include +#include +#include +#include #include +#include #ifndef KDE_USE_FINAL KWIN_EFFECT_CONFIG_FACTORY #endif @@ -48,6 +53,13 @@ VideoRecordEffectConfig::VideoRecordEffectConfig(QWidget* parent, const QVariant kDebug() ; QVBoxLayout* layout = new QVBoxLayout(this); + QHBoxLayout* hlayout = new QHBoxLayout( this ); + QLabel *label = new QLabel( i18n( "Path to save video:" ), this ); + hlayout->addWidget( label ); + saveVideo = new KUrlRequester( this ); + saveVideo->setMode( KFile::Directory | KFile::LocalOnly ); + hlayout->addWidget( saveVideo ); + layout->addLayout( hlayout ); KActionCollection* actionCollection = new KActionCollection( this, KComponentData("kwin") ); KAction* a = static_cast(actionCollection->addAction( "VideoRecord" )); a->setText( i18n("Toggle Video Recording" )); @@ -73,6 +85,8 @@ void VideoRecordEffectConfig::load() kDebug() ; KCModule::load(); + KConfigGroup conf = EffectsHandler::effectConfig("VideoRecord"); + saveVideo->setPath( conf.readEntry( "videopath", KGlobalSettings::documentPath() ) ); emit changed(false); } @@ -81,6 +95,12 @@ void VideoRecordEffectConfig::save() kDebug() ; KCModule::save(); + KConfigGroup conf = EffectsHandler::effectConfig("VideoRecord"); + + conf.writeEntry("videopath", saveVideo->url().path()); + + conf.sync(); + emit changed(false); EffectsHandler::sendReloadMessage( "videorecord" ); } @@ -88,6 +108,7 @@ void VideoRecordEffectConfig::save() void VideoRecordEffectConfig::defaults() { kDebug() ; + saveVideo->setPath(KGlobalSettings::documentPath() ); mShortcutEditor->allDefault(); emit changed(true); } diff --git a/effects/videorecord_config.h b/effects/videorecord_config.h index 9f5a0bf0b3..e6ce824da2 100644 --- a/effects/videorecord_config.h +++ b/effects/videorecord_config.h @@ -26,6 +26,7 @@ along with this program. If not, see . #undef KDE3_SUPPORT class KShortcutsEditor; +class KUrlRequester; namespace KWin { @@ -44,6 +45,7 @@ class VideoRecordEffectConfig : public KCModule private: KShortcutsEditor* mShortcutEditor; + KUrlRequester *saveVideo; }; } // namespace