Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

preferences.cc

Go to the documentation of this file.
00001 /*
00002 * Copyright (C) 2001-2007 Dan Dennedy <dan@dennedy.org>
00003 *
00004 * This program is free software; you can redistribute it and/or modify
00005 * it under the terms of the GNU General Public License as published by
00006 * the Free Software Foundation; either version 2 of the License, or
00007 * (at your option) any later version.
00008 *
00009 * This program is distributed in the hope that it will be useful,
00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 * GNU General Public License for more details.
00013 *
00014 * You should have received a copy of the GNU General Public License
00015 * along with this program; if not, write to the Free Software Foundation,
00016 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017 */
00018 
00019 
00020 #ifdef HAVE_CONFIG_H
00021 #include <config.h>
00022 #endif
00023 
00024 #include "preferences.h"
00025 #include "kino_common.h"
00026 #include "stringutils.h"
00027 
00028 #include <stdlib.h>
00029 #include <stdio.h>
00030 #include <errno.h>
00031 
00032 #include <string>
00033 using std::string;
00034 using std::make_pair;
00035 #include <sstream>
00036 #include <iostream>
00037 
00038 #define GKEYFILE_GROUP "general"
00039 
00040 static string kino_config_file()
00041 {
00042     static string filename;
00043 
00044     if(!filename.size())
00045     {
00046         char *kinoHome=getenv("KINO_HOME");
00047 
00048         if(kinoHome)
00049             filename=string(kinoHome)+string("/kinorc");
00050         else
00051             filename = string( getenv( "HOME" ) ) + string( "/.kinorc" );
00052     }
00053 
00054     return filename;
00055 }
00056 
00062 Preferences *Preferences::instance = NULL;
00063 
00071 Preferences &Preferences::getInstance()
00072 {
00073     if ( instance == NULL )
00074     {
00075         instance = new Preferences;
00076     }
00077     return *instance;
00078 }
00079 
00080 void Preferences::get( int& var, const char* name, const char* def )
00081 {
00082     GError *err = NULL;
00083     var = g_key_file_get_integer( config, GKEYFILE_GROUP, name, &err );
00084     if ( err != NULL )
00085     {
00086         var = atoi( def );
00087         g_key_file_set_integer( config, GKEYFILE_GROUP, name, var );
00088         g_error_free (err);
00089     }
00090 }
00091 
00092 void Preferences::get( char *var, int size, const char* name, const char* def )
00093 {
00094     gchar *temp = g_key_file_get_string( config, GKEYFILE_GROUP, name, NULL );
00095     if ( temp != NULL )
00096     {
00097         strncpy( var, temp, size - 1 );
00098         g_free( temp );
00099     }
00100     else
00101     {
00102         strncpy( var, def, size - 1 );
00103         g_key_file_set_string( config, GKEYFILE_GROUP, name, def );
00104     }
00105 }
00106 
00107 void Preferences::get( bool& var, const char* name, const char* def )
00108 {
00109     GError *err = NULL;
00110     var = g_key_file_get_boolean( config, GKEYFILE_GROUP, name, &err );
00111     if ( err != NULL )
00112     {
00113         var = strcmp( def, "false" );
00114         g_key_file_set_boolean( config, GKEYFILE_GROUP, name, var );
00115         g_error_free (err);
00116     }
00117 }
00118 
00119 
00125 Preferences::Preferences() : phyID( -1 )
00126 {
00127     char* key = new char[4096];
00128     string filename;
00129     
00130     // Give the new config file priority, but failover to the old gnome-config one
00131     filename = kino_config_file();
00132     FILE *f = fopen( filename.c_str(), "r" );
00133     if ( f )
00134         fclose( f );
00135     else
00136         // Try to load old config if nothing yet found
00137         filename = string( getenv( "HOME" ) ) + string( "/.gnome2/kino" );
00138     
00139     // Read the config file
00140     config = g_key_file_new();
00141     g_key_file_load_from_file( config, filename.c_str(), G_KEY_FILE_KEEP_COMMENTS, NULL );
00142 
00143     // Put the config entries into member vars with defaults
00144     get( file, sizeof(file), "file", "capture" );
00145     get( defaultNormalisation, "defaultNormalisation", "0" );
00146     get( defaultAudio, "defaultAudio", "2" );
00147     get( defaultAspect, "defaultAspect", "0" );
00148     snprintf( key, 4096, "%d", RAW_FORMAT );
00149     get( fileFormat, "fileFormat", key );
00150     get( autoSplit, "autoSplit", "true" );
00151     get( timeStamp, "timeStamp", "false" );
00152     get( frames, "frames", "0" );
00153     get( every, "every", "1" );
00154     get( interface, "interface", "0" );
00155     get( channel, "channel", "63" );
00156     get( avcGUID, sizeof(avcGUID), "avcGUID", "" );
00157     snprintf( key, 4096, "%d", DISPLAY_XV );
00158     get( displayMode, "displayMode", key );
00159     get( displayQuality, "displayQuality", "2" );
00160     get( displayFixed, "displayFixed", "false" );
00161     get( enableAudio, "enableAudio", "true" );
00162     get( cip_n, "cip_increment", "0" );
00163     get( cip_d, "cip_threshold", "0" );
00164     get( syt_offset, "syt_offset", "0" );
00165     get( preview_capture, "preview_capture", "true" );
00166     get( dropFrame, "dropFrame", "true" );
00167     get( audioDevice, sizeof(audioDevice), "audioDevice", "default" );
00168     get( enableV4L, "enableV4L", "false" );
00169     get( disableKeyRepeat, "disableKeyRepeat", "false" );
00170     get( audioRendering, "audioRendering", "0" );
00171     get( maxUndos, "maxUndos", "50" );
00172     get( dvCaptureBuffers, "dvCaptureBuffers", "50" );
00173     get( dvExportBuffers, "dvExportBuffers", "10" );
00174     get( dvDecoderClampLuma, "dvDecoderClampLuma", "false" );
00175     get( dvDecoderClampChroma, "dvDecoderClampChroma", "false" );
00176     get( maxFileSize, "maxFileSize", "0" );
00177     get( audioScrub, "audioScrub", "false" );
00178     get( v4lVideoDevice, sizeof(v4lVideoDevice), "v4lVideoDevice", "/dev/video0" );
00179     get( v4lAudioDevice, sizeof(v4lAudioDevice), "v4lAudioDevice", "/dev/dsp" );
00180     get( v4lInput, sizeof(v4lInput), "v4lInput", "PAL" );
00181     get( v4lAudio, sizeof(v4lAudio), "v4lAudio", "32000" );
00182     get( isOpenDML, "isOpenDML", "false" );
00183     get( defaultDirectory, sizeof(defaultDirectory), "defaultDirectory", "~/" );
00184     get( displayExtract, "displayExtract", "1" );
00185     get( relativeSave, "relativeSave", "true" );
00186     get( dvCaptureDevice, sizeof(dvCaptureDevice), "dvCaptureDevice", "/dev/dv1394/0" );
00187     get( dv1394Preview, "dv1394Preview", "true" );
00188     get( dvExportDevice, sizeof(dvExportDevice), "dvExportDevice", "/dev/dv1394/0" );
00189     get( avcPollIntervalMs, "avcPollIntervalMs", "200" );
00190     get( dvExportPrerollSec, "dvExportPrerollSec", "4" );
00191     get( dvTwoPassEncoder, "dvTwoPassEncoder", "true" );
00192     get( windowWidth, "windowWidth", "-1" );
00193     get( windowHeight, "windowHeight", "-1" );
00194     get( storyboardPosition, "storyboardPosition", "-1" );
00195     get( previewSize, "previewSize", "0" );
00196     get( timeFormat, "timeFormat", "3" );
00197     get( trimModeInsert, "trimModeInsert", "false" );
00198     get( enablePublish, "enablePublish", "true" );
00199     get( expandStoryboard, "expandStoryboard", "false" );
00200     get( newProjectURI, sizeof(newProjectURI), "newProjectURI", "" );
00201     get( newProjectXPath, sizeof(newProjectXPath), "newProjectXPath", "" );
00202     get( metaNames, sizeof(metaNames), "metaNames", "*title,author,copyright,id,abstract" );
00203     get( enableAVC, "enableAVC", "true" );
00204 
00205     get( exportMjpegFormat, "exportMjpegFormat", "6" );
00206     get( exportMjpegAspect, "exportMjpegAspect", "0" );
00207     get( exportMjpegDeinterlace, "exportMjpegDeinterlace", "0" );
00208     get( exportMjpegSceneSplit, "exportMjpegSceneSplit", "false" );
00209     get( exportMjpegCleanup, "exportMjpegCleanup", "true" );
00210     get( exportMjpegDvdTool, "exportMjpegDvdTool", "1" );
00211     get( exportMjpegVideoPipe, sizeof(exportMjpegVideoPipe), "exportMjpegVideoPipe", "mpeg2enc -v 0" );
00212     get( exportMjpegAudioPipe, sizeof(exportMjpegAudioPipe), "exportMjpegAudioPipe", "mp2enc -v 0" );
00213     get( exportMjpegMultiplex, sizeof(exportMjpegMultiplex), "exportMjpegMultiplex", "mplex -v 0" );
00214 
00215     // build a metaValues key for each metaName
00216     // metaValues is a range of values to pick from
00217     // metaValue * = open-ended, values outside range permitted, can be used alongside values
00218     vector< string > metaNamesList;
00219     vector< string >::iterator metaNamesIter;
00220     
00221     StringUtils::split( metaNames, ",", metaNamesList );
00222     for ( metaNamesIter = metaNamesList.begin(); metaNamesIter != metaNamesList.end(); ++metaNamesIter )
00223     
00224     {
00225         std::ostringstream str;
00226         std::string metaname = *metaNamesIter;
00227 
00228         if ( metaname.at( 0 ) == '*' )
00229             metaname.erase( 0, 1 );
00230 
00231         str << "metaValues_" << metaname;
00232         if ( metaname == "copyright" )
00233             get( key, 4096, str.str().c_str(), "No license (All rights reserved)=-1,Creative Commons Attribution=1,Creative Commons Attribution-NoDerivs=2,Creative Commons Attribution-NonCommercial-NoDerivs=3,Creative Commons Attribution-NonCommercial=4,Creative Commons Attribution-NonCommercial-ShareAlike=5,Creative Commons Attribution-ShareAlike=6,Public Domain=7,*" );
00234         else
00235             get( key, 4096, str.str().c_str(), "*" );
00236         {
00237             vector< string > metaValuesSimpleList;
00238             vector< string >::iterator iter;
00239             vector< pair< string, string > > metaValuesList;
00240 
00241             StringUtils::split( key, ",", metaValuesSimpleList );
00242             for ( iter = metaValuesSimpleList.begin(); iter != metaValuesSimpleList.end(); ++iter )
00243             {
00244                 vector< string > labelValueVector;
00245                 pair< string, string > labelValuePair;
00246                 
00247                 StringUtils::split( *iter, "=", labelValueVector );
00248                 if ( labelValueVector.size() > 1 )
00249                     labelValuePair = make_pair( labelValueVector[0], labelValueVector[1] );
00250                 else
00251                     labelValuePair = make_pair( *iter, *iter );
00252                 metaValuesList.push_back( labelValuePair );
00253             }
00254             metaValues.insert( make_pair( metaname, metaValuesList ) );
00255         }
00256     }
00257 
00258     JogShuttleInit();
00259     RecentFilesInit();
00260     
00261     Save();
00262     delete[] key;
00263 }
00264 
00265 
00266 Preferences::~Preferences()
00267 {
00268     g_key_file_free( config );
00269 }
00270 
00276 void Preferences::JogShuttleInit(void)
00277 {
00279     get( enableJogShuttle, "enableJogShuttle", "false" );
00280     _isGrabbing = false;
00281     /* Fill array of actions */
00282     /* Element 0 is empty */
00283     int count = 0; 
00284     /* "<none>" should always go first */
00285     _JogShuttleActions.push_back(
00286         JogShuttleActions( count++, _( "<none>" ),
00287                            "",
00288                            "" ) );
00289 
00290     _JogShuttleActions.push_back(
00291         JogShuttleActions( count++,
00292                            _( "Toggle play" ),
00293                            _( "Toggle between play and pause" ),
00294                            " " ) );
00295     
00296     JogShuttleInitNavigation(count);
00297     JogShuttleInitCut(count);
00298     JogShuttleInitCopy(count);
00299     JogShuttleInitPaste(count);
00300     JogShuttleInitModeSwitching(count);
00301     JogShuttleInitGeneral(count);
00302     JogShuttleInitTrim(count);
00303 
00304     // TODO: Add more actions?
00305 
00306     /* Actually get the preferences */
00307     get( count, "jogShuttleNumMappings", "0" );
00308     if ( 0 != count )
00309     {
00310         for ( int i = 0; i < count ; i++ )
00311         {
00312             char key[ 512 ];
00313             sprintf( key, "jogShuttleMappingFirstButton%i", i );
00314             int first_code;
00315             get( first_code, key, "0" );
00316             sprintf( key, "jogShuttleMappingSecondButton%i", i );
00317             int second_code;
00318             get( second_code, key, "0" );
00319             sprintf( key, "jogShuttleMappingAction%i", i );
00320             // g_print ( " Key = %s\n", key );
00321             get( key, sizeof(key), key, "" );
00322 
00323             // TODO: Free
00324             // g_print( "tmpstring Read action %s\n", tempString );
00325             string action = string( key );
00326             // g_print( "Read action %s\n", action.c_str() );
00327             /* Insert */
00328             _JogShuttleMappings[ make_pair ( first_code, second_code ) ]
00329             = JogShuttleMapping( action );
00330         }
00331     }
00332     else
00333     {
00334         // Set up defaults manuall, if 0 count
00335         // These are my own default mappings
00336         _JogShuttleMappings[ make_pair ( 0x100, 0x0 ) ]
00337         = JogShuttleMapping( "i" );
00338         _JogShuttleMappings[ make_pair ( 0x101, 0x0 ) ]
00339         = JogShuttleMapping( "o" );
00340         _JogShuttleMappings[ make_pair ( 0x102, 0x0 ) ]
00341         = JogShuttleMapping( "h" );
00342         _JogShuttleMappings[ make_pair ( 0x103, 0x0 ) ]
00343         = JogShuttleMapping( "l" );
00344         
00345         _JogShuttleMappings[ make_pair ( 0x113, 0x0 ) ]
00346         = JogShuttleMapping( "b" );
00347         _JogShuttleMappings[ make_pair ( 0x111, 0x0 ) ]
00348         = JogShuttleMapping( "w" );
00349         _JogShuttleMappings[ make_pair ( 0x110, 0x0 ) ]
00350         = JogShuttleMapping( " " );
00351         _JogShuttleMappings[ make_pair ( 0x112, 0x0 ) ]
00352         = JogShuttleMapping( "k" );
00353         _JogShuttleMappings[ make_pair ( 0x114, 0x0 ) ]
00354         = JogShuttleMapping( "j" );
00355         _JogShuttleMappings[ make_pair ( 0x115, 0x0 ) ]
00356         = JogShuttleMapping( "gg" );
00357         _JogShuttleMappings[ make_pair ( 0x116, 0x0 ) ]
00358         = JogShuttleMapping( "G" );
00359         
00360         _JogShuttleMappings[ make_pair ( 0x10, 0x0 ) ]
00361         = JogShuttleMapping( " " );
00362     }
00363 }
00364 
00366 void Preferences::JogShuttleInitNavigation(int& count)
00367 {
00368     _JogShuttleActions.push_back(
00369         JogShuttleActions( count++, _( "Forward one frame" ),
00370                            _( "Move one frame forward" ),
00371                            "l" ) );
00372 
00373     _JogShuttleActions.push_back(
00374         JogShuttleActions( count++, _( "Back one frame" ),
00375                            _( "Move one frame backward" ),
00376                            "h" ) );
00377 
00378     _JogShuttleActions.push_back(
00379         JogShuttleActions( count++, _( "Forward one second" ),
00380                            _( "Move one second forward" ),
00381                            "w" ) );
00382 
00383     _JogShuttleActions.push_back(
00384         JogShuttleActions( count++, _( "Forward 30 seconds" ),
00385                            _( "Move 30 seconds forward" ),
00386                            "30w" ) );
00387 
00388     _JogShuttleActions.push_back(
00389         JogShuttleActions( count++, _( "Back one second" ),
00390                            _( "Move one second backward" ),
00391                            "b" ) );
00392 
00393 
00394     _JogShuttleActions.push_back(
00395         JogShuttleActions( count++, _( "Back 30 seconds" ),
00396                            _( "Move 30 seconds backward" ),
00397                            "30b" ) );
00398 
00399     _JogShuttleActions.push_back(
00400         JogShuttleActions( count++, _( "Start of scene" ),
00401                            _( "Move to start of current scene" ),
00402                            "0" ) );
00403 
00404     _JogShuttleActions.push_back(
00405         JogShuttleActions( count++, _( "End of scene" ),
00406                            _( "Move to end of current scene" ),
00407                            "$" ) );
00408 
00409     _JogShuttleActions.push_back(
00410         JogShuttleActions( count++, _( "Previous scene" ),
00411                            _( "Move to start of previous scene" ),
00412                            "k" ) );
00413 
00414     _JogShuttleActions.push_back(
00415         JogShuttleActions( count++, _( "Next scene" ),
00416                            _( "Move to start of next scene" ),
00417                            "j" ) );
00418 
00419     _JogShuttleActions.push_back(
00420         JogShuttleActions( count++, _( "First frame" ),
00421                            _( "Move to beginning of movie" ),
00422                            "gg" ) );
00423 
00424     _JogShuttleActions.push_back(
00425         JogShuttleActions( count++, _( "Last frame" ),
00426                            _( "Move to end of movie" ),
00427                            "G" ) );
00428 
00429     _JogShuttleActions.push_back(
00430         JogShuttleActions( count++, _( "Forward 5 scenes" ),
00431                            _( "Move forward 5 scenes" ),
00432                            "5$" ) );
00433 
00434     _JogShuttleActions.push_back(
00435         JogShuttleActions( count++, _( "Back 5 scene" ),
00436                            _( "Move backward 5 scenes" ),
00437                            "5^" ) );
00438 }
00439 
00441 void Preferences::JogShuttleInitCut(int& count)
00442 {
00443     _JogShuttleActions.push_back(
00444         JogShuttleActions( count++, _( "Cut current frame" ),
00445                            _( "Cut current frame" ),
00446                            "x" ) );
00447 
00448     _JogShuttleActions.push_back(
00449         JogShuttleActions( count++, _( "Cut a second" ),
00450                            _( "Cut a second" ),
00451                            "dw" ) );
00452 
00453     _JogShuttleActions.push_back(
00454         JogShuttleActions( count++, _( "Cut current scene" ),
00455                            _( "Cut current scene" ),
00456                            "dd" ) );
00457 
00458     _JogShuttleActions.push_back(
00459         JogShuttleActions( count++, _( "Cut to end of current scene" ),
00460                            _( "Cut to end of current scene" ),
00461                            "d$" ) );
00462 
00463     _JogShuttleActions.push_back(
00464         JogShuttleActions( count++, _( "Cut to end of movie" ),
00465                            _( "Cut to end of movie" ),
00466                            "dG" ) );
00467 
00468     _JogShuttleActions.push_back(
00469         JogShuttleActions( count++, _( "Cut from start of current scene" ),
00470                            _( "Cut from start of current scene" ),
00471                            "d0" ) );
00472 
00473     _JogShuttleActions.push_back(
00474         JogShuttleActions( count++, _( "Cut from start of movie" ),
00475                            _( "Cut from start of movie" ),
00476                            "dgg" ) );
00477 }
00478 
00480 void Preferences::JogShuttleInitCopy(int& count)
00481 {
00482     _JogShuttleActions.push_back(
00483         JogShuttleActions( count++, _( "Copy current scene" ),
00484                            _( "Copy current scene" ),
00485                            "yy" ) );
00486 
00487     _JogShuttleActions.push_back(
00488         JogShuttleActions( count++, _( "Copy to end of scene" ),
00489                            _( "Copy to end of scene" ),
00490                            "y$" ) );
00491 
00492     _JogShuttleActions.push_back(
00493         JogShuttleActions( count++, _( "Copy from start of scene" ),
00494                            _( "Cut from start of scene" ),
00495                            "y0" ) );
00496 }
00497 
00499 void Preferences::JogShuttleInitPaste(int& count)
00500 {
00501     _JogShuttleActions.push_back(
00502         JogShuttleActions( count++, _( "Paste after current frame" ),
00503                            _( "Paste after current frame" ),
00504                            "p" ) );
00505 
00506     _JogShuttleActions.push_back(
00507         JogShuttleActions( count++, _( "Paste before current frame" ),
00508                            _( "Paste before current frame" ),
00509                            "P" ) );
00510 }
00511 
00513 void Preferences::JogShuttleInitModeSwitching(int& count)
00514 {
00515     _JogShuttleActions.push_back(
00516         JogShuttleActions( count++, _( "Switch to Edit" ),
00517                            _( "Switch to the edit interface" ),
00518                            "F2" ) );
00519 
00520     _JogShuttleActions.push_back(
00521         JogShuttleActions( count++, _( "Switch to Capture" ),
00522                            _( "Switch to the capture interface" ),
00523                            "A" ) );
00524 
00525     _JogShuttleActions.push_back(
00526         JogShuttleActions( count++, _( "Switch to Timeline" ),
00527                            _( "Switch to the capture interface" ),
00528                            "v" ) );
00529 
00530     _JogShuttleActions.push_back(
00531         JogShuttleActions( count++, _( "Switch to Export" ),
00532                            _( "Switch to the capture interface" ),
00533                            ":W" ) );
00534 
00535     _JogShuttleActions.push_back(
00536         JogShuttleActions( count++, _( "Switch to FX" ),
00537                            _( "Switch to the capture interface" ),
00538                            "C" ) );
00539 
00540     _JogShuttleActions.push_back(
00541         JogShuttleActions( count++, _( "Switch to Trim" ),
00542                            _( "Switch to trim mode" ),
00543                            "t" ) );
00544 }
00545 
00547 void Preferences::JogShuttleInitGeneral(int& count)
00548 {
00549     _JogShuttleActions.push_back(
00550         JogShuttleActions( count++, _( "Repeat last command" ),
00551                            _( "Repeat last command" ),
00552                            "." ) );
00553 
00554     _JogShuttleActions.push_back(
00555         JogShuttleActions( count++, _( "Split scene" ),
00556                            _( "Split scene before current frame" ),
00557                            "Ctrl+J" ) );
00558 
00559     _JogShuttleActions.push_back(
00560         JogShuttleActions( count++, _( "Join scenes" ),
00561                            _( "Join this scene with the following" ),
00562                            "J" ) );
00563 
00564     _JogShuttleActions.push_back(
00565         JogShuttleActions( count++, _( "Undo" ),
00566                            _( "Undo last command" ),
00567                            "u" ) );
00568 
00569     _JogShuttleActions.push_back(
00570         JogShuttleActions( count++, _( "Redo" ),
00571                            _( "Redo last command" ),
00572                            "Ctrl+R" ) );
00573                            
00574     _JogShuttleActions.push_back(
00575         JogShuttleActions( count++, _( "Capture/Overwrite/Export/Render" ),
00576                            _( "Start Capture, Export, or Render or Apply Overwrite" ),
00577                            "Enter" ) );
00578 
00579     _JogShuttleActions.push_back(
00580         JogShuttleActions( count++, _( "Stop" ),
00581                            _( "Stop transport, capture, export, or render" ),
00582                            "Esc" ) );
00583 
00584     _JogShuttleActions.push_back(
00585         JogShuttleActions( count++, _( "Publish SMIL" ),
00586                            _( "Publish SMIL" ),
00587                            "Ctrl+W" ) );
00588 }
00589 
00591 void Preferences::JogShuttleInitTrim(int& count)
00592 {
00593     _JogShuttleActions.push_back(
00594         JogShuttleActions( count++, _( "Set In" ),
00595                            _( "Set the In Point to current position" ),
00596                            "i" ) );
00597 
00598     _JogShuttleActions.push_back(
00599         JogShuttleActions( count++, _( "Set Out" ),
00600                            _( "Set the Out Point to current position" ),
00601                            "o" ) );
00602 
00603     _JogShuttleActions.push_back(
00604         JogShuttleActions( count++, _( "Insert Before" ),
00605                            _( "Insert Before" ),
00606                            ":r" ) );
00607 
00608     _JogShuttleActions.push_back(
00609         JogShuttleActions( count++, _( "Insert After" ),
00610                            _( "Insert After" ),
00611                            ":a" ) );
00612 
00613     _JogShuttleActions.push_back(
00614         JogShuttleActions( count++, _( "Toggle Insert/Overwrite" ),
00615                            _( "Toggle Insert/Overwrite" ),
00616                            "Ins" ) );
00617                            
00618     _JogShuttleActions.push_back(
00619         JogShuttleActions( count++, _( "Toggle Looping" ),
00620                            _( "Toggle Looping" ),
00621                            "\\" ) );
00622 
00623     _JogShuttleActions.push_back(
00624         JogShuttleActions( count++, _( "Toggle Link" ),
00625                            _( "Toggle Link" ),
00626                            "=" ) );
00627 }
00631 void Preferences::set( const char *name, const char* value )
00632 {
00633     g_key_file_set_string( config, GKEYFILE_GROUP, name, value );
00634 }
00635 
00636 void Preferences::set( const char *name, int value )
00637 {
00638     g_key_file_set_integer( config, GKEYFILE_GROUP, name, value );
00639 }
00640 
00641 void Preferences::set( const char *name, bool value )
00642 {
00643     g_key_file_set_boolean( config, GKEYFILE_GROUP, name, value );
00644 }
00645 
00647 void
00648 Preferences::Save()
00649 {
00650     set( "defaultNormalisation", defaultNormalisation );
00651     set( "defaultAudio", defaultAudio );
00652     set( "defaultAspect", defaultAspect );
00653     set( "file", file );
00654     set( "fileFormat", fileFormat );
00655     set( "autoSplit", autoSplit );
00656     set( "timeStamp", timeStamp );
00657     set( "frames", frames );
00658     set( "every", every );
00659     set( "interface", interface );
00660     set( "channel", channel );
00661     set( "avcGUID", avcGUID );
00662     set( "displayMode", displayMode );
00663     set( "displayQuality", displayQuality );
00664     set( "displayFixed", displayFixed );
00665     set( "enableAudio", enableAudio );
00666     set( "cip_increment", cip_n );
00667     set( "cip_threshold", cip_d );
00668     set( "syt_offset", syt_offset );
00669     set( "preview_capture", preview_capture );
00670     set( "dropFrame", dropFrame );
00671     set( "audioDevice", audioDevice );
00672 
00673     /* JogShuttle Stuff */
00674     set( "enableJogShuttle", enableJogShuttle );
00675     set( "jogShuttleNumMappings", static_cast< int >( _JogShuttleMappings.size() ) );
00676     int count = 0;
00677     map<pair<unsigned short, unsigned short>, JogShuttleMapping>::iterator i;
00678     pair<unsigned short, unsigned short> map_key;
00679     for ( i = _JogShuttleMappings.begin();
00680             i != _JogShuttleMappings.end() ; i++, count++ )
00681     {
00682         map_key = ( *i ).first;
00683         char key[ 512 ];
00684         sprintf( key, "jogShuttleMappingFirstButton%i", count );
00685         set( key, map_key.first );
00686         sprintf( key, "jogShuttleMappingSecondButton%i", count );
00687         set( key, map_key.second );
00688         sprintf( key, "jogShuttleMappingAction%i", count );
00689         set( key, ( *i ).second._action.c_str() );
00690     }
00691 
00692     set( "enableV4L", enableV4L );
00693     set( "disableKeyRepeat", disableKeyRepeat );
00694     set( "audioRendering", audioRendering );
00695     set( "maxUndos", maxUndos );
00696     set( "dvCaptureBuffers", dvCaptureBuffers );
00697     set( "dvExportBuffers", dvExportBuffers );
00698     set( "dvDecoderClampLuma", dvDecoderClampLuma );
00699     set( "dvDecoderClampChroma", dvDecoderClampChroma );
00700     set( "maxFileSize", maxFileSize );
00701     set( "audioScrub", audioScrub );
00702     set( "v4lVideoDevice", v4lVideoDevice );
00703     set( "v4lAudioDevice", v4lAudioDevice );
00704     set( "v4lInput", v4lInput );
00705     set( "v4lAudio", v4lAudio );
00706     set( "isOpenDML", isOpenDML );
00707     set( "defaultDirectory", defaultDirectory );
00708     set( "displayExtract", displayExtract );
00709     set( "relativeSave", relativeSave );
00710 
00711     set( "dvCaptureDevice", dvCaptureDevice );
00712     set( "dv1394Preview", dv1394Preview );
00713     set( "dvExportDevice", dvExportDevice );
00714     set( "avcPollIntervalMs", avcPollIntervalMs );
00715     set( "dvExportPrerollSec", dvExportPrerollSec );
00716     set( "dvTwoPassEncoder", dvTwoPassEncoder );
00717     set( "windowWidth", windowWidth );
00718     set( "windowHeight", windowHeight );
00719     set( "storyboardPosition", storyboardPosition );
00720     set( "previewSize", previewSize );
00721     set( "timeFormat", timeFormat );
00722     set( "metaNames", metaNames );
00723     set( "enablePublish", enablePublish );
00724     set( "expandStoryboard", expandStoryboard );
00725     set( "newProjectURI", newProjectURI );
00726     set( "newProjectXPath", newProjectXPath );
00727     set( "trimModeInsert", trimModeInsert );
00728     set( "enableAVC", enableAVC );
00729     
00730     set( "exportMjpegFormat", exportMjpegFormat );
00731     set( "exportMjpegDeinterlace", exportMjpegDeinterlace );
00732     set( "exportMjpegAspect", exportMjpegAspect );
00733     set( "exportMjpegSceneSplit", exportMjpegSceneSplit );
00734     set( "exportMjpegCleanup", exportMjpegCleanup );
00735     set( "exportMjpegDvdTool", exportMjpegDvdTool );
00736     set( "exportMjpegVideoPipe", exportMjpegVideoPipe );
00737     set( "exportMjpegAudioPipe", exportMjpegAudioPipe );
00738     set( "exportMjpegMultiplex", exportMjpegMultiplex );
00739 
00740     RecentFilesSave();
00741 
00742     // Persist
00743     string filename = kino_config_file();
00744     FILE *f = fopen( filename.c_str(), "w" );
00745     if ( f )
00746     {
00747         gsize data_size = 0;
00748         gchar *data = g_key_file_to_data( config, &data_size, NULL );
00749         fwrite( data, data_size, 1, f );
00750         fclose( f );
00751         g_free( data );
00752     }
00753     
00754     // Delete the old file if it exists (ignore error)
00755     filename = string( getenv( "HOME" ) ) + string( "/.gnome2/kino" );
00756     unlink( filename.c_str() );
00757     errno = 0;
00758 }
00759 
00760 void Preferences::RecentFilesInit()
00761 {
00762     char* key = new char[64];
00763     char* value = new char[ PATH_MAX + NAME_MAX ];
00764 
00765     for ( int i = 0; i < 5 ; i++ )
00766     {
00767         sprintf( key, "recentFile%i", i );
00768         value[0] = 0;
00769         get( value, PATH_MAX + NAME_MAX, key, "" );
00770         if ( strcmp( value, "" ) )
00771             recentFiles.push_back( value );
00772     }
00773     
00774     delete[] key;
00775     delete[] value;
00776 }
00777 
00778 void Preferences::RecentFilesSave()
00779 {
00780     vector<string>::iterator i;
00781     int count = 0;
00782 
00783     for ( i = recentFiles.begin(); i != recentFiles.end(); i++, count++ )
00784     {
00785         char key[64];
00786         sprintf( key, "recentFile%i", count );
00787         set( key, (*i).c_str() );
00788     }
00789 }
00790 
00791 void Preferences::addRecentFile( string filename )
00792 {
00793     vector<std::string>::iterator i;
00794     for ( i = recentFiles.begin(); i != recentFiles.end(); i++ )
00795     {
00796         if ( (*i) == filename )
00797         {
00798             recentFiles.erase( i );
00799             recentFiles.push_back( filename );
00800             break;
00801         }
00802     }
00803     if ( i == recentFiles.end() )
00804     {
00805         if ( recentFiles.size() > 4 )
00806             recentFiles.erase( recentFiles.begin() );
00807         recentFiles.push_back( filename );
00808     }
00809 }

Generated on Sun Mar 11 22:11:47 2007 for Kino by  doxygen 1.4.2