~kelemeng/banshee/bug743928

« back to all changes in this revision

Viewing changes to src/Dap/Banshee.Dap.Ipod/Banshee.Dap.Ipod/UnsupportedDatabaseView.cs

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2011-05-14 22:25:36 UTC
  • mfrom: (6.3.15 experimental)
  • Revision ID: james.westby@ubuntu.com-20110514222536-u1x7ikxdqkmfvyuz
Tags: 2.1.0-1ubuntu1
* [2396c18] Merge from Debian Unstable, remaining changes:
  + Enable SoundMenu and Disable NotificationArea by default
  + Disable boo and karma extensions
  + Enable and recommnd u1ms and soundmenu extensions
  + Move desktop file for Meego UI to /usr/share/une/applications
  + Change the url for the Amazon store redirector
  + Create the U1MS widget earlier and bump libu1 requirement
* [9d7c600] Drop upstreamed u1ms-initialize-earlier patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// UnsupportedDatabaseView.cs
3
 
//
4
 
// Author:
5
 
//   Aaron Bockover <abockover@novell.com>
6
 
//
7
 
// Copyright (C) 2006-2008 Novell, Inc.
8
 
//
9
 
// Permission is hereby granted, free of charge, to any person obtaining
10
 
// a copy of this software and associated documentation files (the
11
 
// "Software"), to deal in the Software without restriction, including
12
 
// without limitation the rights to use, copy, modify, merge, publish,
13
 
// distribute, sublicense, and/or sell copies of the Software, and to
14
 
// permit persons to whom the Software is furnished to do so, subject to
15
 
// the following conditions:
16
 
//
17
 
// The above copyright notice and this permission notice shall be
18
 
// included in all copies or substantial portions of the Software.
19
 
//
20
 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
 
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
 
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
 
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
 
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
 
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
 
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
 
//
28
 
 
29
 
using System;
30
 
using System.IO;
31
 
using Mono.Unix;
32
 
using Gtk;
33
 
using IPod;
34
 
 
35
 
using Hyena;
36
 
using Hyena.Widgets;
37
 
 
38
 
using Banshee.Gui;
39
 
using Banshee.Widgets;
40
 
 
41
 
using Banshee.Dap.Gui;
42
 
 
43
 
namespace Banshee.Dap.Ipod
44
 
{
45
 
    public class UnsupportedDatabaseView : DapPropertiesDisplay
46
 
    {
47
 
        private MessagePane pane;
48
 
        private bool info_link_clicked = false;
49
 
        private IpodSource source;
50
 
 
51
 
        public event EventHandler Refresh;
52
 
 
53
 
        public UnsupportedDatabaseView (IpodSource source) : base (source)
54
 
        {
55
 
            this.source = source;
56
 
 
57
 
            pane = new MessagePane();
58
 
            pane.HeaderIcon = IconThemeUtils.LoadIcon(48, "face-surprise", Stock.DialogError);
59
 
            pane.ArrowIcon = IconThemeUtils.LoadIcon(24, "go-next", Stock.GoForward);
60
 
            pane.HeaderMarkup = String.Format("<big><b>{0}</b></big>",
61
 
                GLib.Markup.EscapeText(Catalog.GetString("Unable to read your iPod")));
62
 
 
63
 
            AddPaneItems();
64
 
 
65
 
            Add(pane);
66
 
            ShowAll ();
67
 
        }
68
 
 
69
 
        private void AddPaneItems()
70
 
        {
71
 
            if(info_link_clicked) {
72
 
                bool file_exists = System.IO.File.Exists (Paths.Combine (
73
 
                    source.IpodDevice.ControlPath, "iTunes", "iTunesDB"));
74
 
 
75
 
                if(file_exists) {
76
 
                    pane.Append(Catalog.GetString(
77
 
                        "You have used this iPod with a version of iTunes that saves a " +
78
 
                        "version of the song database for your iPod that is too new " +
79
 
                        "for Banshee to recognize.\n\n" +
80
 
 
81
 
                        "Banshee can rebuild your database, but you might lose your settings and all the content in the device (be sure to backup your data first). " +
82
 
                        "Using Banshee and iTunes with the same iPod is not recommended."
83
 
                    ));
84
 
 
85
 
                    LinkLabel link = new LinkLabel();
86
 
                    link.Xalign = 0.0f;
87
 
                    link.Markup = String.Format("<u>{0}</u>", GLib.Markup.EscapeText(Catalog.GetString(
88
 
                        "Learn more about Banshee's iPod support")));
89
 
 
90
 
                    link.Clicked += delegate { Banshee.Web.Browser.Open ("http://banshee.fm/IpodAndItunes"); };
91
 
 
92
 
                    link.Show();
93
 
                    pane.Append(link, Gtk.AttachOptions.Expand | Gtk.AttachOptions.Fill, 0, true);
94
 
                } else {
95
 
                    pane.Append(Catalog.GetString(
96
 
                        "An iPod database could not be found on this device.\n\n" +
97
 
                        "Banshee can build a new database for you."
98
 
                    ));
99
 
                }
100
 
            } else {
101
 
                LinkLabel link = new LinkLabel();
102
 
                link.Xalign = 0.0f;
103
 
                link.Markup = String.Format("<u>{0}</u>", GLib.Markup.EscapeText(Catalog.GetString(
104
 
                    "What is the reason for this?")));
105
 
 
106
 
                link.Clicked += delegate {
107
 
                    info_link_clicked = true;
108
 
                    pane.Clear();
109
 
                    AddPaneItems();
110
 
                };
111
 
 
112
 
                link.Show();
113
 
                pane.Append(link, Gtk.AttachOptions.Expand | Gtk.AttachOptions.Fill, 0, true);
114
 
            }
115
 
 
116
 
            if(source.IpodDevice.VolumeInfo.IsMountedReadOnly) {
117
 
                pane.Append(Catalog.GetString("Your iPod is mounted read only. Banshee can not restore your iPod."),
118
 
                    true, IconThemeUtils.LoadIcon(48, "dialog-error"));
119
 
                return;
120
 
            }
121
 
 
122
 
            LinkLabel rebuild_link = new LinkLabel();
123
 
            rebuild_link.Xalign = 0.0f;
124
 
            rebuild_link.Markup = String.Format("<u>{0}</u>", GLib.Markup.EscapeText(Catalog.GetString(
125
 
                "Rebuild iPod Database...")));
126
 
            rebuild_link.Clicked += OnRebuildDatabase;
127
 
            rebuild_link.Show();
128
 
            pane.Append(rebuild_link, Gtk.AttachOptions.Expand | Gtk.AttachOptions.Fill, 0, true);
129
 
        }
130
 
 
131
 
        private void OnRebuildDatabase(object o, EventArgs args)
132
 
        {
133
 
            string title = Catalog.GetString("Confirm Rebuild iPod Database");
134
 
            HigMessageDialog md = new HigMessageDialog(null,
135
 
                DialogFlags.DestroyWithParent, MessageType.Question,
136
 
                ButtonsType.Cancel,
137
 
                title,
138
 
                Catalog.GetString(
139
 
                    "Rebuilding your iPod database may take some time. Also note that " +
140
 
                    "any playlists you have on your iPod will be lost.\n\n" +
141
 
                    "Are you sure you want to rebuild your iPod database?"));
142
 
            md.Title = title;
143
 
            md.AddButton(Catalog.GetString("Rebuild Database"), Gtk.ResponseType.Yes, true);
144
 
 
145
 
            if(md.Run() != (int)ResponseType.Yes) {
146
 
                md.Destroy();
147
 
                return;
148
 
            }
149
 
 
150
 
            md.Destroy();
151
 
 
152
 
            pane.HeaderIcon = null;
153
 
            pane.HeaderMarkup = null;
154
 
 
155
 
            pane.Clear();
156
 
            pane.Append(String.Format("<big><b>{0}</b></big>",
157
 
                GLib.Markup.EscapeText(Catalog.GetString("Rebuilding iPod Database..."))),
158
 
                true, LargeIcon);
159
 
 
160
 
            DatabaseRebuilder rebuilder = new DatabaseRebuilder(source);
161
 
            rebuilder.Finished += delegate {
162
 
                OnRefresh ();
163
 
            };
164
 
        }
165
 
 
166
 
        protected virtual void OnRefresh()
167
 
        {
168
 
            EventHandler handler = Refresh;
169
 
            if (handler != null) {
170
 
                handler (this, new EventArgs ());
171
 
            }
172
 
        }
173
 
    }
174
 
}