fix some bugs and crashes

This commit is contained in:
Hylke Bons 2010-07-22 22:10:38 +01:00
parent 3191ea70e0
commit 9481449358
7 changed files with 343 additions and 45 deletions

View file

@ -0,0 +1,30 @@
// SparkleShare, an instant update workflow to Git.
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
//
// This program 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.
//
// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
using System;
namespace SparkleShare {
public class Defines {
public const string VERSION = "@VERSION@";
public const string LOCALE_DIR = "@prefix@/share/locale";
public const string GETTEXT_PACKAGE = "@GETTEXT_PACKAGE@";
public const string PREFIX = "@prefix@";
}
}

View file

@ -12,7 +12,7 @@
// GNU General private License for more details.
//
// You should have received a copy of the GNU General private License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using Gtk;
using Mono.Unix;
@ -268,7 +268,7 @@ namespace SparkleShare {
}
// Enables or disables the "Next" button depending on the
// Enables or disables the 'Next' button depending on the
// entries filled in by the user
private void CheckFields ()
{
@ -361,7 +361,6 @@ namespace SparkleShare {
process.StartInfo.FileName = "ssh-keygen";
process.StartInfo.Arguments = "-t rsa -P " + user_email + " -f " + key_file_name;
process.WaitForExit ();
process.Start ();
process.Exited += delegate {

View file

@ -12,7 +12,7 @@
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using Gtk;
using Mono.Unix;
@ -25,7 +25,7 @@ using System.Timers;
namespace SparkleShare {
// SparkleRepo class holds repository information and timers
// Holds repository information and timers
public class SparkleRepo
{
@ -55,8 +55,14 @@ namespace SparkleShare {
public delegate void PushedEventHandler (object o, SparkleEventArgs args);
public event PushedEventHandler Pushed;
public delegate void FetchedEventHandler (object o, SparkleEventArgs args);
public event FetchedEventHandler Fetched;
public delegate void FetchingStartedEventHandler (object o, SparkleEventArgs args);
public event FetchingStartedEventHandler FetchingStarted;
public delegate void FetchingFinishedEventHandler (object o, SparkleEventArgs args);
public event FetchingFinishedEventHandler FetchingFinished;
public delegate void NewCommitEventHandler (object o, SparkleEventArgs args);
public event NewCommitEventHandler NewCommit;
public static string _ (string s)
@ -221,9 +227,6 @@ namespace SparkleShare {
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes staged.");
// SparkleUI.NotificationIcon.SetSyncingState ();
// SparkleUI.NotificationIcon.SetIdleState ();
SparkleEventArgs args = new SparkleEventArgs ("Added");
if (Added != null)
@ -258,7 +261,11 @@ namespace SparkleShare {
FetchTimer.Stop ();
// SparkleUI.NotificationIcon.SetSyncingState ();
SparkleEventArgs args;
args = new SparkleEventArgs ("FetchingStarted");
if (FetchingStarted != null)
FetchingStarted (this, args);
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Fetching changes...");
@ -270,16 +277,15 @@ namespace SparkleShare {
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Changes fetched.");
SparkleEventArgs args = new SparkleEventArgs ("Fetched");
args = new SparkleEventArgs ("FetchingFinished");
if (Fetched != null)
Fetched (this, args);
if (FetchingFinished != null)
FetchingFinished (this, args);
// Rebase if there are changes
if (!Output.Contains ("up to date"))
Rebase ();
// SparkleUI.NotificationIcon.SetIdleState ();
} finally {
FetchTimer.Start ();
@ -297,7 +303,7 @@ namespace SparkleShare {
SparkleHelpers.DebugInfo ("Git", "[" + Name + "] Rebasing changes...");
Process.StartInfo.Arguments = "rebase origin";
Process.StartInfo.Arguments = "rebase -v master";
Process.WaitForExit ();
Process.Start ();
@ -339,7 +345,7 @@ namespace SparkleShare {
Process.Start ();
string conflict_title = "A mid-air collision happened!\n";
string conflict_subtext = "Don't worry, SparkleShare made\na copy of the conflicting files.";
string conflict_subtext = "Don't worry, SparkleShare made\na copy of each conflicting file.";
// SparkleBubble ConflictBubble =
// new SparkleBubble(_(ConflictTitle), _(ConflictSubtext));
@ -385,6 +391,11 @@ namespace SparkleShare {
SparkleHelpers.DebugInfo ("Notification", "[" + Name + "] Showing message...");
SparkleEventArgs args = new SparkleEventArgs ("NewCommit");
if (NewCommit != null)
NewCommit (this, args);
// SparkleBubble StuffChangedBubble = new SparkleBubble (LastCommitUserName, LastCommitMessage);
// StuffChangedBubble.Icon = SparkleHelpers.GetAvatar (LastCommitEmail, 32);

View file

@ -30,7 +30,6 @@ namespace SparkleShare {
return Catalog.GetString (s);
}
public static SparkleRepo [] Repositories;
public static SparkleUI SparkleUI;
public static void Main (string [] args)

View file

@ -0,0 +1,254 @@
// SparkleShare, an instant update workflow to Git.
// Copyright (C) 2010 Hylke Bons <hylkebons@gmail.com>
//
// This program 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.
//
// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
using Gtk;
using Mono.Unix;
using SparkleShare;
using System;
using System.Diagnostics;
using System.IO;
using System.Timers;
namespace SparkleShare {
public class SparkleStatusIcon : StatusIcon
{
private Timer Timer;
private int SyncingState;
public int SyncingReposCount;
// Short alias for the translations
public static string _ (string s) {
return Catalog.GetString (s);
}
public EventHandler CreateWindowDelegate (SparkleRepo SparkleRepo)
{
return delegate {
SparkleWindow SparkleWindow = new SparkleWindow (SparkleRepo);
SparkleWindow.ShowAll ();
};
}
public SparkleStatusIcon () : base ()
{
Timer = new Timer ();
Activate += ShowMenu;
SyncingReposCount = 0;
// 0 = Everything up to date
// 1 = Syncing in progress
// -1 = Error syncing
SyncingState = 0;
SetIdleState ();
}
public void ShowMenu (object o, EventArgs Args)
{
Menu Menu = new Menu ();
string StateText = "";
switch (SyncingState) {
case -1:
StateText = _("Error syncing");
break;
case 0:
StateText = _("Everything is up to date");
break;
case 1:
StateText = _("Syncing…");
break;
}
MenuItem StatusMenuItem = new MenuItem (StateText);
StatusMenuItem.Sensitive = false;
Menu.Add (StatusMenuItem);
Menu.Add (new SeparatorMenuItem ());
Gtk.Action FolderAction = new Gtk.Action ("", "SparkleShare Folder");
FolderAction.IconName = "folder-sparkleshare";
FolderAction.IsImportant = true;
FolderAction.Activated += delegate {
Process Process = new Process ();
switch (SparklePlatform.Name) {
case "GNOME":
Process.StartInfo.FileName = "xdg-open";
break;
case "OSX":
Process.StartInfo.FileName = "open";
break;
}
Process.StartInfo.Arguments = SparklePaths.SparklePath;
Process.Start ();
};
Menu.Add (FolderAction.CreateMenuItem ());
Gtk.Action [] FolderItems =
new Gtk.Action [SparkleUI.Repositories.Length];
int i = 0;
foreach (SparkleRepo SparkleRepo in SparkleUI.Repositories) {
FolderItems [i] = new Gtk.Action ("", SparkleRepo.Name);
FolderItems [i].IconName = "folder";
FolderItems [i].IsImportant = true;
FolderItems [i].Activated += CreateWindowDelegate (SparkleRepo);
Menu.Add (FolderItems [i].CreateMenuItem ());
i++;
}
MenuItem AddItem = new MenuItem (_("Add Remote Folder…"));
AddItem.Activated += delegate {
SparkleDialog SparkleDialog = new SparkleDialog ("");
SparkleDialog.ShowAll ();
};
Menu.Add (AddItem);
Menu.Add (new SeparatorMenuItem ());
CheckMenuItem NotifyCheckMenuItem = new CheckMenuItem (_("Show Notifications"));
Menu.Add (NotifyCheckMenuItem);
Menu.Add (new SeparatorMenuItem ());
string NotifyChangesFileName = SparkleHelpers.CombineMore (SparklePaths.SparkleConfigPath,
"sparkleshare.notify");
if (System.IO.File.Exists (NotifyChangesFileName))
NotifyCheckMenuItem.Active = true;
NotifyCheckMenuItem.Toggled += delegate {
if (System.IO.File.Exists (NotifyChangesFileName)) {
File.Delete (NotifyChangesFileName);
} else {
System.IO.File.Create (NotifyChangesFileName);
}
};
MenuItem AboutItem = new MenuItem (_("About"));
AboutItem.Activated += delegate {
Process Process = new Process ();
switch (SparklePlatform.Name) {
case "GNOME":
Process.StartInfo.FileName = "xdg-open";
break;
case "OSX":
Process.StartInfo.FileName = "open";
break;
}
Process.StartInfo.Arguments = "http://www.sparkleshare.org/";
Process.Start ();
};
Menu.Add (AboutItem);
Menu.Add (new SeparatorMenuItem ());
MenuItem QuitItem = new MenuItem (_("Quit"));
QuitItem.Activated += Quit;
Menu.Add (QuitItem);
Menu.ShowAll ();
Menu.Popup (null, null, SetPosition, 0, Global.CurrentEventTime);
}
public void UpdateState ()
{
if (SyncingReposCount > 0)
SetSyncingState ();
else
SetIdleState ();
}
public void SetIdleState ()
{
Timer.Stop ();
IconName = "folder-sparkleshare";
SyncingState = 0;
}
// Changes the status icon to the syncing animation
// TODO: There are UI freezes when switching back and forth
// bewteen syncing and idle state
public void SetSyncingState ()
{
IconName = "view-refresh";
SyncingState = 1;
/* int CycleDuration = 250;
int CurrentStep = 0;
int Size = 24;
Gdk.Pixbuf SpinnerGallery = SparkleHelpers.GetIcon ("process-syncing-sparkleshare", Size);
int FramesInWidth = SpinnerGallery.Width / Size;
int FramesInHeight = SpinnerGallery.Height / Size;
int NumSteps = FramesInWidth * FramesInHeight;
Gdk.Pixbuf [] Images = new Gdk.Pixbuf [NumSteps - 1];
int i = 0;
for (int y = 0; y < FramesInHeight; y++) {
for (int x = 0; x < FramesInWidth; x++) {
if (!(y == 0 && x == 0)) {
Images [i] = new Gdk.Pixbuf (SpinnerGallery, x * Size, y * Size, Size, Size);
i++;
}
}
}
Timer = new Timer ();
Timer.Interval = CycleDuration / NumSteps;
Timer.Elapsed += delegate {
if (CurrentStep < NumSteps)
CurrentStep++;
else
CurrentStep = 0;
Pixbuf = Images [CurrentStep];
};
Timer.Start ();
*/
}
// Changes the status icon to the error icon
public void SetErrorState ()
{
IconName = "folder-sync-error";
SyncingState = -1;
}
public void SetPosition (Menu menu, out int x, out int y, out bool push_in)
{
PositionMenu (menu, out x, out y, out push_in, Handle);
}
// Quits the program
public void Quit (object o, EventArgs args)
{
System.IO.File.Delete (SparkleHelpers.CombineMore (SparklePaths.SparkleTmpPath, "sparkleshare.pid"));
Application.Quit ();
}
}
}

View file

@ -12,7 +12,7 @@
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using Gtk;
using Mono.Unix;
@ -27,6 +27,7 @@ namespace SparkleShare {
public class SparkleUI {
private Process Process;
public static SparkleRepo [] Repositories;
// Short alias for the translations
public static string _(string s)
@ -64,7 +65,7 @@ namespace SparkleShare {
NotificationIcon = new SparkleStatusIcon ();
// Show a notification if there are no folders yet
if (SparkleShare.Repositories.Length == 0) {
if (Repositories.Length == 0) {
SparkleBubble NoFoldersBubble;
NoFoldersBubble = new SparkleBubble (_("Welcome to SparkleShare!"),
@ -238,11 +239,27 @@ namespace SparkleShare {
}
public void Test (object o, SparkleEventArgs args) {
public void ShowNewCommitBubble (object o, SparkleEventArgs args) {
Console.WriteLine ("AAAAAAAAAAAAAAAAAA");
}
public void UpdateStatusIcon (object o, SparkleEventArgs args) {
if (args.Message.Equals ("FetchingStarted")) {
NotificationIcon.SyncingReposCount++;
NotificationIcon.UpdateState ();
}
if (args.Message.Equals ("FetchingFinished")) {
NotificationIcon.SyncingReposCount--;
NotificationIcon.UpdateState ();
}
}
// TODO: Make this a List instead of an array
public void UpdateRepositories ()
{
@ -257,32 +274,18 @@ namespace SparkleShare {
if (Directory.Exists (SparkleHelpers.CombineMore (folder, ".git"))) {
TmpRepos [FolderCount] = new SparkleRepo (folder);
TmpRepos [FolderCount].NewCommit += ShowNewCommitBubble;
TmpRepos [FolderCount].FetchingStarted += UpdateStatusIcon;
TmpRepos [FolderCount].FetchingFinished += UpdateStatusIcon;
FolderCount++;
// TODO: emblems don't show up in nautilus
// Attach emblems
switch (SparklePlatform.Name) {
case "GNOME":
Process.StartInfo.FileName = "gvfs-set-attribute";
Process.StartInfo.Arguments = "-t string \"" + folder +
"\" metadata::emblems [synced]";
Process.Start ();
break;
}
}
}
SparkleRepo a = TmpRepos [0];
a.Added += Test;
SparkleShare.Repositories = new SparkleRepo [FolderCount];
Array.Copy (TmpRepos, SparkleShare.Repositories, FolderCount);
Repositories = new SparkleRepo [FolderCount];
Array.Copy (TmpRepos, Repositories, FolderCount);
}

View file

@ -99,13 +99,15 @@ namespace SparkleShare {
private ScrolledWindow CreateEventLog ()
{
int number_of_events = 50;
Process process = new Process ();
process.EnableRaisingEvents = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.WorkingDirectory = SparkleRepo.LocalPath;
process.StartInfo.FileName = "git";
process.StartInfo.Arguments = "log --format=\"%at☃%an☃%ae☃%s\" -50";
process.StartInfo.Arguments = "log --format=\"%at☃%an☃%ae☃%s\" -" + number_of_events;
string output = "";
@ -122,7 +124,7 @@ namespace SparkleShare {
List <ActivityDay> activity_days = new List <ActivityDay> ();
for (int i = 0; i < 25 && i < lines.Length; i++) {
for (int i = 0; i < number_of_events && i < lines.Length; i++) {
string line = lines [i];
@ -214,7 +216,7 @@ namespace SparkleShare {
}
layout_vertical.PackStart (date_label, true, true, 0);
layout_vertical.PackStart (date_label, false, false, 0);
IconView icon_view = new IconView (list_store) {
ItemWidth = 480,
@ -224,7 +226,7 @@ namespace SparkleShare {
Spacing = 9
};
layout_vertical.PackStart (icon_view);
layout_vertical.PackStart (icon_view, false, false, 0);
}