Created
December 22, 2009 12:28
-
-
Save bolthar/261712 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MangaViewModel < FreightViewModel | |
signal :update_progress | |
region :mangas | |
region :chapters | |
region :page | |
region :control_box | |
service :download | |
service :scheduler | |
service :caching | |
attr_reader :status | |
attr_reader :version | |
def self.container_options | |
return { :model => :singleton } | |
end | |
def initialize | |
@status = "Ready." | |
@progress = 0 | |
super | |
@view.update | |
end | |
def set_elements(elements) | |
mangas.set_mangas(elements) unless mangas.mangas | |
end | |
def get_elements | |
return mangas.mangas | |
end | |
def on_pick_manga | |
viewmodel = FindMangaViewModel.new | |
viewmodel.on_ok = method(:add_manga) | |
viewmodel.show | |
end | |
def on_show_about | |
Freightrain[:about_view_model].show | |
end | |
def mangas_on_selected(manga) | |
chapters.manga_selected(manga) | |
end | |
def chapters_on_progress_changed(message = "Ready.", total = 1, completed = 0) | |
fire :update_progress, message, total, completed | |
end | |
def mangas_on_progress_changed(message = "Ready.", total = 1, completed = 0) | |
fire :update_progress, message, total, completed | |
end | |
def update_progress(message, total, completed) | |
@status = message | |
@completed = completed | |
@total = total | |
@view.update | |
end | |
def chapters_on_selected(chapter) | |
control_box.chapter_changed(chapter) | |
mangas.update_status | |
end | |
def page_on_ask_next_page | |
control_box.next_page | |
end | |
def control_box_on_page_changed(changed_page) | |
page.page_changed(changed_page) | |
end | |
def progress | |
return 0 if @completed == @total | |
return @completed.to_f / @total.to_f | |
end | |
def percentage | |
return "" if progress == 0 | |
return (progress * 100).to_i.to_s + " %" | |
end | |
def version | |
return "v. 1.2.2" | |
end | |
def add_manga(manga) | |
mangas.add_manga(manga) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment