Check for a new version on start up (issue 27)

This commit is contained in:
Alexander Kojevnikov 2010-07-07 18:33:56 +10:00
parent 1a3ced87c4
commit df52ab83b6
6 changed files with 124 additions and 3 deletions

View File

@ -24,12 +24,12 @@ AM_PROG_VALAC([0.7.0])
AC_PROG_INSTALL
AC_PROG_INTLTOOL([0.35])
pkg_modules="gtk+-2.0 >= 2.14.0 libavformat libavcodec >= 52.23.0"
pkg_modules="gtk+-2.0 >= 2.18.0 libavformat libavcodec >= 52.23.0"
PKG_CHECK_MODULES(SPEK, [$pkg_modules])
AC_SUBST(SPEK_CFLAGS)
AC_SUBST(SPEK_LIBS)
SPEK_PACKAGES="--pkg gtk+-2.0 --pkg posix"
SPEK_PACKAGES="--pkg gtk+-2.0 --pkg gio-2.0 --pkg posix"
AC_SUBST(SPEK_PACKAGES)
AC_CHECK_LIB(m, log10f)

View File

@ -4,6 +4,7 @@ spek_SOURCES = \
spek.vala \
spek-audio.c \
spek-fft.c \
spek-message-bar.vala \
spek-pipeline.vala \
spek-ruler.vala \
spek-spectrogram.vala \

81
src/spek-message-bar.vala Normal file
View File

@ -0,0 +1,81 @@
/* spek-message-bar.vala
*
* Copyright (C) 2010 Alexander Kojevnikov <alexander@kojevnikov.com>
*
* Spek is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Spek is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Spek. If not, see <http://www.gnu.org/licenses/>.
*
* This class is heavily influenced by its namesake from Banshee.
* The original code by Aaron Bockover is (c) 2008 Novell, Inc.
*/
using Gtk;
namespace Spek {
public class MessageBar : HBox {
private Label label;
private Gtk.Window win;
public MessageBar (string message) {
homogeneous = false;
spacing = 0;
border_width = 6;
win = new Gtk.Window (WindowType.POPUP);
win.name = "gtk-tooltips";
win.ensure_style ();
win.style_set.connect (() => style = win.style);
label = new Label (null);
label.use_markup = true;
label.set_markup (message);
label.ellipsize = Pango.EllipsizeMode.END;
label.xalign = 0f;
var button_box = new HBox (false, 0);
button_box.spacing = 3;
var close_button = new Button ();
close_button.image = new Gtk.Image.from_stock (STOCK_CLOSE, IconSize.MENU);
close_button.relief = ReliefStyle.NONE;
close_button.clicked.connect (() => hide ());
pack_start (label, true, true, 0);
pack_start (button_box, false, false, 0);
pack_start (close_button, false, false, 0);
}
private bool changing_style = false;
private override void style_set (Style? previous_style) {
if (changing_style) {
return;
}
changing_style = true;
style = win.style;
label.style = style;
changing_style = false;
}
private override bool expose_event (Gdk.EventExpose event) {
if (!is_drawable ()) {
return false;
}
var cr = Gdk.cairo_create (event.window);
var color = style.bg[StateType.NORMAL];
cr.set_source_rgb (color.red / 65535.0, color.green / 65535.0, color.blue / 65535.0);
cr.rectangle (allocation.x, allocation.y, allocation.width, allocation.height);
cr.fill ();
return base.expose_event (event);
}
}
}

View File

@ -23,6 +23,7 @@ namespace Spek {
public class Window : Gtk.Window {
private const string full_title = _("Spek - Acoustic Spectrum Analyser");
private MessageBar message_bar;
private Spectrogram spectrogram;
private string cur_dir;
private FileFilter filter_all;
@ -79,6 +80,8 @@ namespace Spek {
about.clicked.connect (on_about_clicked);
toolbar.insert (about, -1);
message_bar = new MessageBar (_("A new version of Spek is available on <a href=\"http://www.spek-project.org\">www.spek-project.org</a>"));
spectrogram = new Spectrogram ();
cur_dir = Environment.get_home_dir ();
@ -96,9 +99,13 @@ namespace Spek {
var vbox = new VBox (false, 0);
vbox.pack_start (toolbar, false, true, 0);
vbox.pack_start (message_bar, false, true, 0);
vbox.pack_start (spectrogram, true, true, 0);
add (vbox);
show_all ();
toolbar.show_all ();
spectrogram.show_all ();
vbox.show ();
show ();
// Set up Drag and Drop
drag_dest_set (this, DestDefaults.ALL, DEST_TARGET_ENTRIES, DragAction.COPY);
@ -107,6 +114,11 @@ namespace Spek {
if (file_name != null) {
open_file (file_name);
}
try {
Thread.create (check_version, false);
} catch (ThreadError e) {
}
}
void on_dropped (DragContext cx, int x, int y, SelectionData data, uint info, uint time) {
@ -242,5 +254,26 @@ namespace Spek {
"*.wma",
"*.wv"
};
private void * check_version () {
// TODO: don't check on each start up.
var file = File.new_for_uri ("http://www.spek-project.org/version");
if (!file.query_exists (null)) {
return null;
}
string version;
try {
var stream = new DataInputStream (file.read (null));
version = stream.read_line (null, null);
} catch (Error e) {
return null;
}
if (version != null && version > Config.PACKAGE_VERSION) {
Idle.add (() => { message_bar.show_all (); return false; });
}
return null;
}
}
}

View File

@ -14,6 +14,11 @@ handlers:
upload: robots.txt
mime_type: text/plain
- url: /version
static_files: version
upload: version
mime_type: text/plain
- url: /
static_files: index.html
upload: index.html

1
web/version Normal file
View File

@ -0,0 +1 @@
0.5