static void
set_cell (GtkCellLayout   *cell_layout,
	  GtkCellRenderer *cell,
	  GtkTreeModel    *tree_model,
	  GtkTreeIter     *iter,
	  gpointer         data)
{
	gboolean header;
	gchar *text;
	Itdb_IpodInfo *info;

	gtk_tree_model_get (tree_model, iter, COL_INFO, &info, -1);
	g_return_if_fail (info);

	header = gtk_tree_model_iter_has_child (tree_model, iter);

	if (header) {
		text = g_strdup (
				 itdb_info_get_ipod_generation_string (info->ipod_generation));
	} else {
		text = ipod_info_to_string (info);
	}

	g_object_set (cell,
		      "sensitive", !header,
		      "text", text,
		      NULL);
	g_free (text);
}
Esempio n. 2
0
void set_cell(GtkCellLayout *cell_layout, GtkCellRenderer *cell, GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data) {
    gboolean header;
    gchar *text;
    IpodInfo *info;

    gtk_tree_model_get(tree_model, iter, COL_POINTER, &info, -1);
    g_return_if_fail (info);

    header = gtk_tree_model_iter_has_child(tree_model, iter);

    if (header) {
        text = g_strdup(itdb_info_get_ipod_generation_string(info->ipod_generation));
    }
    else {
        if (info->capacity >= 1) { /* size in GB */
            text
                    = g_strdup_printf(_("%2.0f GB %s (x%s)"), info->capacity, itdb_info_get_ipod_model_name_string(info->ipod_model), info->model_number);
        }
        else if (info->capacity > 0) { /* size in MB */
            text
                    = g_strdup_printf(_("%3.0f MB %s (x%s)"), info->capacity * 1024, itdb_info_get_ipod_model_name_string(info->ipod_model), info->model_number);
        }
        else { /* no capacity information available */
            text
                    = g_strdup_printf(_("%s (x%s)"), itdb_info_get_ipod_model_name_string(info->ipod_model), info->model_number);
        }
    }

    g_object_set(cell, "sensitive", !header, "text", text, NULL);

    g_free(text);
}
Esempio n. 3
0
static bool
safeToWriteWithMessage( const QString &mountPoint, const Itdb_iTunesDB *itdb, QString &message )
{
    const Itdb_IpodInfo *info = getIpodInfo( itdb ); // returns null on null itdb
    if( !info )
    {
        message = i18n( "iPod model was not recognized." );
        return false;
    }

    QString gen = QString::fromUtf8( itdb_info_get_ipod_generation_string( info->ipod_generation ) );
    if( firewireGuidNeeded( info->ipod_generation ) )
    {
        // okay FireWireGUID may be in plain SysInfo, too, but it's hard to check and
        // error-prone so we just require SysInfoExtended which is machine-generated
        const QString sysInfoExtended( "SysInfoExtended" );
        bool sysInfoExtendedExists = fileFound( mountPoint, sysInfoExtended );
        message += ( sysInfoExtendedExists )
                   ? i18n( "%1 family uses %2 file to generate correct database checksum.",
                           gen, sysInfoExtended )
                   : i18n( "%1 family needs %2 file to generate correct database checksum.",
                           gen, sysInfoExtended );
        if( !sysInfoExtendedExists )
            return false;
    }
    if( hashInfoNeeded( info->ipod_generation ) )
    {
        const QString hashInfo( "HashInfo" );
        bool hashInfoExists = fileFound( mountPoint, hashInfo );
        message += hashInfoExists
                   ? i18n( "%1 family uses %2 file to generate correct database checksum.",
                           gen, hashInfo )
                   : i18n( "%1 family needs %2 file to generate correct database checksum.",
                           gen, hashInfo );
        if( !hashInfoExists )
            return false;
    }
    if( hashAbNeeded( info->ipod_generation ) )
    {
        message += i18nc( "Do not translate hash-AB, libgpod, libhashab.so",
            "%1 family probably uses hash-AB to generate correct database checksum. "
            "libgpod (as of version 0.8.2) doesn't know how to compute it, but tries "
            "to dynamically load external library libhashab.so to do it.", gen
        );
        // we don't return false, user may have hash-AB support installed
    }
    return true;
}
Esempio n. 4
0
static void
fillInModelComboBox( QComboBox *comboBox, bool someSysInfoFound )
{
    if( someSysInfoFound )
    {
        comboBox->addItem( i18n( "Autodetect (%1 file(s) present)", QString( "SysInfo") ), QString() );
        comboBox->setEnabled( false );
        return;
    }

    const Itdb_IpodInfo *info = itdb_info_get_ipod_info_table();
    if( !info )
    {
        // this is not i18n-ed for purpose: it should never happen
        comboBox->addItem( QString( "Failed to get iPod info table!" ), QString() );
        return;
    }

    while( info->model_number )
    {
        QString generation = QString::fromUtf8( itdb_info_get_ipod_generation_string( info->ipod_generation) );
        QString capacity = KGlobal::locale()->formatByteSize( info->capacity * 1073741824.0, 0 );
        QString modelName = QString::fromUtf8( itdb_info_get_ipod_model_name_string( info->ipod_model ) );
        QString modelNumber = QString::fromUtf8( info->model_number );
        QString label = i18nc( "Examples: "
                               "%1: Nano with camera (5th Gen.); [generation]"
                               "%2: 16 GiB; [capacity]"
                               "%3: Nano (Orange); [model name]"
                               "%4: A123 [model number]",
                               "%1: %2 %3 [%4]",
                               generation, capacity, modelName, modelNumber );
        comboBox->addItem( label, modelNumber );
        info++; // list is ended by null-filled info
    }
    comboBox->setMaxVisibleItems( 16 );
}
Esempio n. 5
0
void
IpodDeviceHelper::fillInConfigureDialog( KDialog *configureDialog,
                                         Ui::IpodConfiguration *configureDialogUi,
                                         const QString &mountPoint,
                                         Itdb_iTunesDB *itdb,
                                         const Transcoding::Configuration &transcodeConfig,
                                         const QString &errorMessage )
{
    static const QString unknown = i18nc( "Unknown iPod model, generation...", "Unknown" );
    static const QString supported = i18nc( "In a dialog: Video: Supported", "Supported" );
    static const QString notSupported = i18nc( "In a dialog: Video: Not supported", "Not supported" );
    static const QString present = i18nc( "In a dialog: Some file: Present", "Present" );
    static const QString notFound = i18nc( "In a dialog: Some file: Not found", "<b>Not found</b>" );
    static const QString notNeeded = i18nc( "In a dialog: Some file: Not needed", "Not needed" );

    // following call accepts null itdb
    configureDialogUi->nameLineEdit->setText( IpodDeviceHelper::ipodName( itdb ) );
    QString notes;
    QString warningText;
    QString safeToWriteMessage;
    bool isSafeToWrite = safeToWriteWithMessage( mountPoint, itdb, safeToWriteMessage );
    bool sysInfoExtendedExists = fileFound( mountPoint, "SysInfoExtended" );
    bool sysInfoExists = fileFound( mountPoint, "SysInfo" );

    if( itdb )
    {
        configureDialogUi->nameLineEdit->setEnabled( isSafeToWrite );
        configureDialogUi->transcodeComboBox->setEnabled( isSafeToWrite );
        configureDialogUi->transcodeComboBox->fillInChoices( transcodeConfig );
        configureDialogUi->modelComboLabel->setEnabled( false );
        configureDialogUi->modelComboBox->setEnabled( false );
        configureDialogUi->initializeLabel->setEnabled( false );
        configureDialogUi->initializeButton->setEnabled( false );
        if( !errorMessage.isEmpty() )
            // to inform user about successful initialization.
            warningText = QString( "<b>%1</b>" ).arg( errorMessage );

        const Itdb_Device *device = itdb->device;
        const Itdb_IpodInfo *info = device ? itdb_device_get_ipod_info( device ) : 0;
        configureDialogUi->infoGroupBox->setEnabled( true );
        configureDialogUi->modelPlaceholer->setText( info ? QString::fromUtf8(
            itdb_info_get_ipod_model_name_string( info->ipod_model ) ) : unknown );
        configureDialogUi->generationPlaceholder->setText( info ? QString::fromUtf8(
            itdb_info_get_ipod_generation_string( info->ipod_generation ) ) : unknown );
        configureDialogUi->videoPlaceholder->setText( device ?
            ( itdb_device_supports_video( device ) ? supported : notSupported ) : unknown );
        configureDialogUi->albumArtworkPlaceholder->setText( device ?
            ( itdb_device_supports_artwork( device ) ? supported : notSupported ) : unknown );

        if( isSafeToWrite )
            notes += safeToWriteMessage; // may be empty, doesn't hurt
        else
        {
            Q_ASSERT( !safeToWriteMessage.isEmpty() );
            const QString link( "http://gtkpod.git.sourceforge.net/git/gitweb.cgi?p=gtkpod/libgpod;a=blob_plain;f=README.overview" );
            notes += i18nc( "%1 is informational sentence giving reason",
                "<b>%1</b><br><br>"
                "As a safety measure, Amarok will <i>refuse to perform any writes</i> to "
                "iPod. (modifying iTunes database could make it look empty from the device "
                "point of view)<br>"
                "See <a href='%2'>README.overview</a> file from libgpod source repository "
                "for more information.",
                safeToWriteMessage, link
            );
        }
    }
    else
    {
        configureDialogUi->nameLineEdit->setEnabled( true ); // for initialization
        configureDialogUi->modelComboLabel->setEnabled( true );
        configureDialogUi->modelComboBox->setEnabled( true );
        if( configureDialogUi->modelComboBox->count() == 0 )
            fillInModelComboBox( configureDialogUi->modelComboBox, sysInfoExists || sysInfoExtendedExists );
        configureDialogUi->initializeLabel->setEnabled( true );
        configureDialogUi->initializeButton->setEnabled( true );
        configureDialogUi->initializeButton->setIcon( KIcon( "task-attention" ) );
        if( !errorMessage.isEmpty() )
            warningText = i18n(
                "<b>%1</b><br><br>"
                "Above problem prevents Amarok from using your iPod. You can try to "
                "re-create critical iPod folders and files (including iTunes database) "
                "using the <b>%2</b> button below.<br><br> "
                "Initializing iPod <b>destroys iPod track and photo database</b>, however "
                "it should not delete any tracks. The tracks will become orphaned.",
                errorMessage,
                configureDialogUi->initializeButton->text().remove( QChar('&') )
            );

        configureDialogUi->infoGroupBox->setEnabled( false );
        configureDialogUi->modelPlaceholer->setText(  unknown );
        configureDialogUi->generationPlaceholder->setText(  unknown );
        configureDialogUi->videoPlaceholder->setText(  unknown );
        configureDialogUi->albumArtworkPlaceholder->setText( unknown );
    }

    if( !warningText.isEmpty() )
    {
        configureDialogUi->initializeLabel->setText( warningText );
        configureDialogUi->initializeLabel->adjustSize();
    }

    QString sysInfoExtendedString = sysInfoExtendedExists ? present : notFound;
    QString sysInfoString = sysInfoExists ? present :
                          ( sysInfoExtendedExists ? notNeeded : notFound );

    configureDialogUi->sysInfoPlaceholder->setText( sysInfoString );
    configureDialogUi->sysInfoExtendedPlaceholder->setText( sysInfoExtendedString );
    configureDialogUi->notesPlaceholder->setText( notes );
    configureDialogUi->notesPlaceholder->adjustSize();

    configureDialog->enableButtonOk( isSafeToWrite );
}
Esempio n. 6
0
/* called by itdb_photodb_add_photo() and
   itdb_photodb_add_photo_from_data() */
static Itdb_Artwork *itdb_photodb_add_photo_internal (Itdb_PhotoDB *db,
						      const gchar *filename,
						      const guchar *image_data,
						      gsize image_data_len,
						      gpointer pixbuf,
						      gint position,
						      gint rotation,
						      GError **error)
{
#ifdef HAVE_GDKPIXBUF
    gboolean result;
    Itdb_Artwork *artwork;
    Itdb_PhotoAlbum *album;
    const Itdb_ArtworkFormat *format;

    g_return_val_if_fail (db, NULL);
    g_return_val_if_fail (db->device, NULL);
    g_return_val_if_fail (filename || image_data, NULL);
    g_return_val_if_fail (!(image_data && (image_data_len == 0)), NULL);
    g_return_val_if_fail (!(pixbuf && (!GDK_IS_PIXBUF (pixbuf))), NULL);

    if (!ipod_supports_photos (db->device))
    {
	const Itdb_IpodInfo *ipodinfo = itdb_device_get_ipod_info (db->device);
	const gchar *model, *generation;

	if (!ipodinfo)
	{
	    g_set_error (error, 0, -1,
			 _("You need to specify the iPod model used before photos can be added."));
	    return NULL;
	    /* For information: The model is set by calling the rather
	       unintuitive function itdb_device_set_sysinfo as
	       follows:

	       itdb_device_set_sysinfo (db->device, "ModelNumStr", model);

	       For example, "MA450" would stand for an 80 GB 6th
	       generation iPod Video. See itdb_device.c for a list of
	       supported models.

	       This information will be written to the iPod when the
	       PhotoDB is saved (itdb_device_write_sysinfo() is called).
	    */
	}

	model = itdb_info_get_ipod_model_name_string (ipodinfo->ipod_model);
	generation = itdb_info_get_ipod_generation_string (ipodinfo->ipod_generation);
	g_return_val_if_fail (model && generation, NULL);
	g_set_error (error, 0, -1,
		     _("Your iPod does not seem to support photos. Maybe you need to specify the correct iPod model number? It is currently set to 'x%s' (%s/%s)."),
		     ipodinfo->model_number, generation, model);
	return NULL;
    }

    /* check if filename is valid */
    if (filename)
    {
	struct stat statbuf;
	if (g_stat  (filename, &statbuf) != 0)
	{
	    g_set_error (error, 0, -1,
			 _("Could not access file '%s'. Photo not added."),
			 filename);
	    return NULL;
	}
    }

    artwork = itdb_artwork_new ();

    /* Add a thumbnail for every supported format */
    format = itdb_device_get_artwork_formats (db->device);
    g_return_val_if_fail (format, NULL);

    for(result = TRUE; format->type != -1 && result == TRUE; format++)
    {
	if((format->type == ITDB_THUMB_COVER_SMALL) ||
	   (format->type == ITDB_THUMB_COVER_LARGE))
	    continue;
	if (filename)
	{
	    result = itdb_artwork_add_thumbnail (artwork,
						 format->type,
						 filename,
						 rotation,
						 error);
	}
	if (image_data)
	{
	    result = itdb_artwork_add_thumbnail_from_data (artwork,
							   format->type,
							   image_data,
							   image_data_len,
							   rotation,
							   error);
	}
	if (pixbuf) 
	{
	  result = itdb_artwork_add_thumbnail_from_pixbuf (artwork,
							   format->type, 
							   pixbuf,
							   rotation,
							   error);
	}
    }

    if (result != TRUE)
    {
	itdb_artwork_free (artwork);
	g_set_error (error, 0, -1,
		     _("Unexpected error in itdb_photodb_add_photo_internal() while adding photo, please report."));
	return NULL;
    }

    /* Add artwork to the list of photos */
    /* (it would be sufficient to append to the end) */
    db->photos = g_list_insert (db->photos, artwork, position);

    /* Add artwork to the first album */
    album = itdb_photodb_photoalbum_by_name (db, NULL);
    if (!album)
    {
	album = itdb_photodb_photoalbum_create (db, _("Photo Library"), -1);
	album->album_type = 1; /* Photo Library */
    }
    itdb_photodb_photoalbum_add_photo (db, album, artwork, position);

    return artwork;
#else
    g_set_error (error, 0, -1,
		 _("Library compiled without gdk-pixbuf support. Picture support is disabled."));
    return NULL;
#endif
}