Skip to content

Commit

Permalink
Merge pull request #1 from hschauhan/master
Browse files Browse the repository at this point in the history
Update Local Fork
  • Loading branch information
arentoine authored May 20, 2020
2 parents b8c546e + 8809c8d commit 0988269
Show file tree
Hide file tree
Showing 7 changed files with 412 additions and 110 deletions.
58 changes: 53 additions & 5 deletions GoSync/GoSyncController.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

ID_SYNC_TOGGLE = wx.NewId()
ID_SYNC_NOW = wx.NewId()
ID_RECALC_USAGE = wx.NewId()

mainWindowStyle = wx.DEFAULT_FRAME_STYLE & (~wx.CLOSE_BOX) & (~wx.MAXIMIZE_BOX) ^ (wx.RESIZE_BORDER)
HERE=os.path.abspath(os.path.dirname(__file__))
Expand Down Expand Up @@ -89,8 +90,14 @@ def OnUsageCalculationDone(self, event):
self.driveUsageBar.SetStatusMessage("Sorry, could not calculate your Google Drive usage.")

def OnUsageCalculationUpdate(self, event):
percent = (event.data * 100)/self.totalFiles
self.driveUsageBar.SetStatusMessage("Calculating your categorical usage... (%d%%)\n" % percent)
self.totalFiles = event.data
self.driveUsageBar.SetStatusMessage("Calculating usage. Files Scanned: %d\n" % self.totalFiles)
self.driveUsageBar.SetMoviesUsage(self.sync_model.GetMovieUsage())
self.driveUsageBar.SetDocumentUsage(self.sync_model.GetDocumentUsage())
self.driveUsageBar.SetOthersUsage(self.sync_model.GetOthersUsage())
self.driveUsageBar.SetAudioUsage(self.sync_model.GetAudioUsage())
self.driveUsageBar.SetPhotoUsage(self.sync_model.GetPhotoUsage())
self.driveUsageBar.RePaint()

def OnUsageCalculationStarted(self, event):
self.totalFiles = event.data
Expand Down Expand Up @@ -135,7 +142,8 @@ def __init__(self):
menu_txt = 'Pause/Resume Sync'

self.CreateMenuItem(menu, menu_txt, self.OnToggleSync, icon=os.path.join(HERE, 'resources/sync-menu.png'), id=ID_SYNC_TOGGLE)
self.CreateMenuItem(menu, 'Synch Now!', self.OnSyncNow, icon=os.path.join(HERE, 'resources/sync-menu.png'), id=ID_SYNC_NOW)
self.CreateMenuItem(menu, 'Sync Now!', self.OnSyncNow, icon=os.path.join(HERE, 'resources/sync-menu.png'), id=ID_SYNC_NOW)
self.CreateMenuItem(menu, 'Recalculate Drive Usage', self.OnRecalculateDriveUsage, icon=os.path.join(HERE, 'resources/sync-menu.png'), id=ID_RECALC_USAGE)

menu.AppendSeparator()
self.CreateMenuItem(menu, 'A&bout', self.OnAbout, os.path.join(HERE, 'resources/info.png'))
Expand Down Expand Up @@ -169,6 +177,7 @@ def __init__(self):
if self.sync_model.IsSyncEnabled():
self.sb.SetStatusText("Running", 1)
else:
self.sb.SetStatusText("")
self.sb.SetStatusText("Paused", 1)

GoSyncEventController().BindEvent(self, GOSYNC_EVENT_SYNC_STARTED,
Expand All @@ -179,15 +188,49 @@ def __init__(self):
self.OnSyncDone)
GoSyncEventController().BindEvent(self, GOSYNC_EVENT_SYNC_TIMER,
self.OnSyncTimer)
GoSyncEventController().BindEvent(self, GOSYNC_EVENT_INTERNET_UNREACHABLE,
self.OnInternetDown)
GoSyncEventController().BindEvent(self, GOSYNC_EVENT_SYNC_INV_FOLDER,
self.OnSyncInvalidFolder)
GoSyncEventController().BindEvent(self, GOSYNC_EVENT_SCAN_UPDATE,
self.OnScanUpdate)
GoSyncEventController().BindEvent(self, GOSYNC_EVENT_CALCULATE_USAGE_DONE,
self.OnUsageCalculationDone)

self.sync_model.SetTheBallRolling()

def OnUsageCalculationDone(self, event):
self.sb.SetStatusText("Usage calculation completed.")

def OnInternetDown(self, event):
self.sb.SetStatusText("Network is down")
self.sb.SetStatusText("Paused", 1)
dial = wx.MessageDialog(None, 'Internet seems to be down. Sync has been paused.\nPlease enable sync after the Internet is reachable.',
'Internet Down', wx.OK | wx.ICON_EXCLAMATION)
res = dial.ShowModal()
dial.Destroy()

def OnSyncInvalidFolder(self, event):
dial = wx.MessageDialog(None, 'Some of the folders to be sync\'ed were not found on remote server.\nPlease check.\n',
dial = wx.MessageDialog(None, 'Folder %s is selected for sync. It could not be found on remote server.\nPlease check settings again.\n' % event.data,
'Error', wx.OK | wx.ICON_EXCLAMATION)
res = dial.ShowModal()
dial.Destroy()

def OnRecalculateDriveUsage(self, event):
if self.sync_model.IsCalculatingDriveUsage() == True:
dial = wx.MessageDialog(None, 'GoSync is already scaningfiles on drive.',
'In Progress', wx.OK | wx.ICON_WARNING)
res = dial.ShowModal()
dial.Destroy()
return
elif self.sync_model.IsSyncRunning() == True:
dial = wx.MessageDialog(None, 'GoSync is currently syncing files from the Drive.\nThe usage will be refreshed later.',
'In Progress', wx.OK | wx.ICON_WARNING)
res = dial.ShowModal()
dial.Destroy()

self.sync_model.ForceDriveUsageCalculation()


def OnSyncTimer(self, event):
unicode_string = event.data.pop()
Expand All @@ -206,6 +249,10 @@ def OnSyncDone(self, event):
else:
self.sb.SetStatusText("Sync failed. Please check the logs.")

def OnScanUpdate(self, event):
unicode_string = event.data.pop()
self.sb.SetStatusText(unicode_string.encode('ascii', 'ignore'))

def CreateMenuItem(self, menu, label, func, icon=None, id=None):
if id:
item = wx.MenuItem(menu, id, label)
Expand Down Expand Up @@ -247,6 +294,7 @@ def OnExit(self, event):
def OnToggleSync(self, evt):
if self.sync_model.IsSyncEnabled():
self.sync_model.StopSync()
self.sb.SetStatusText("Sync is paused")
self.sb.SetStatusText("Paused", 1)
else:
self.sync_model.StartSync()
Expand All @@ -269,7 +317,7 @@ def OnAbout(self, evt):
about.SetWebSite(APP_WEBSITE)
about.SetLicense(APP_LICENSE)
about.AddDeveloper(APP_DEVELOPER)
about.AddArtist(APP_DEVELOPER)
about.AddArtist(ART_DEVELOPER)
if wxgtk4 :
wx.adv.AboutBox(about)
else:
Expand Down
8 changes: 8 additions & 0 deletions GoSync/GoSyncEvents.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
GOSYNC_EVENT_SYNC_DONE = '_gosync_sync_done'
GOSYNC_EVENT_SYNC_TIMER = '_gosync_sync_timer'
GOSYNC_EVENT_SYNC_INV_FOLDER = '_gosync_sync_invalid_folder'
GOSYNC_EVENT_SCAN_UPDATE = '_gosync_scan_update'
GOSYNC_EVENT_INTERNET_UNREACHABLE = '_gosync_internet_unreachable'

GOSYNC_EVENT_ID_SYNC_STARTED = wx.NewId()
GOSYNC_EVENT_ID_SYNC_UPDATE = wx.NewId()
Expand All @@ -35,6 +37,8 @@
GOSYNC_EVENT_ID_CALCULATE_USAGE_DONE = wx.NewId()
GOSYNC_EVENT_ID_SYNC_TIMER = wx.NewId()
GOSYNC_EVENT_ID_SYNC_INV_FOLDER = wx.NewId()
GOSYNC_EVENT_ID_SCAN_UPDATE = wx.NewId()
GOSYNC_EVENT_ID_INTERNET_UNREACHABLE = wx.NewId()

class GoSyncEvent(wx.PyEvent):
def __init__(self, event, data):
Expand All @@ -54,6 +58,8 @@ class GoSyncEventController(object):
GOSYNC_EVENT_CALCULATE_USAGE_UPDATE: GOSYNC_EVENT_ID_CALCULATE_USAGE_UPDATE,
GOSYNC_EVENT_CALCULATE_USAGE_DONE: GOSYNC_EVENT_ID_CALCULATE_USAGE_DONE,
GOSYNC_EVENT_SYNC_TIMER: GOSYNC_EVENT_ID_SYNC_TIMER,
GOSYNC_EVENT_SCAN_UPDATE: GOSYNC_EVENT_ID_SCAN_UPDATE,
GOSYNC_EVENT_INTERNET_UNREACHABLE: GOSYNC_EVENT_ID_INTERNET_UNREACHABLE,
GOSYNC_EVENT_SYNC_INV_FOLDER: GOSYNC_EVENT_ID_SYNC_INV_FOLDER}
_sync_listeners = {GOSYNC_EVENT_SYNC_STARTED:[],
GOSYNC_EVENT_SYNC_UPDATE: [],
Expand All @@ -62,6 +68,8 @@ class GoSyncEventController(object):
GOSYNC_EVENT_CALCULATE_USAGE_UPDATE: [],
GOSYNC_EVENT_CALCULATE_USAGE_DONE: [],
GOSYNC_EVENT_SYNC_TIMER: [],
GOSYNC_EVENT_SCAN_UPDATE: [],
GOSYNC_EVENT_INTERNET_UNREACHABLE: [],
GOSYNC_EVENT_SYNC_INV_FOLDER: []}

def __new__(cls, *args, **kwargs):
Expand Down
Loading

0 comments on commit 0988269

Please sign in to comment.