Exemplo n.º 1
0
func main() {
	opts, args := parseFlags()
	conv := cbconvert.NewConvertor(opts)

	var bar *pb.ProgressBar

	c := make(chan os.Signal, 3)
	signal.Notify(c, os.Interrupt, syscall.SIGHUP, syscall.SIGTERM)
	go func() {
		for _ = range c {
			fmt.Fprintf(os.Stderr, "Aborting\n")
			os.RemoveAll(conv.Workdir)
			os.Exit(1)
		}
	}()

	if _, err := os.Stat(opts.Outdir); err != nil {
		os.MkdirAll(opts.Outdir, 0777)
	}

	files := conv.GetFiles(args)

	if opts.Cover || opts.Thumbnail {
		if !opts.Quiet {
			bar = pb.New(conv.Nfiles)
			bar.ShowTimeLeft = false
			bar.Start()
		}
	}

	for _, file := range files {
		stat, err := os.Stat(file)
		if err != nil {
			fmt.Fprintf(os.Stderr, "Error Stat: %v\n", err.Error())
			continue
		}

		if opts.Cover {
			conv.ExtractCover(file, stat)
			if !opts.Quiet {
				bar.Increment()
			}
			continue
		} else if opts.Thumbnail {
			conv.ExtractThumbnail(file, stat)
			if !opts.Quiet {
				bar.Increment()
			}
			continue
		}

		conv.ConvertComic(file, stat)
	}
}
Exemplo n.º 2
0
func run() error {
	qml.SetWindowIcon(":///assets/icon.png")

	engine := qml.NewEngine()

	c := &Comics{}
	engine.Context().SetVar("c", c)

	engine.AddImportPath("qrc:/assets")
	engine.AddImageProvider("cover", c.CoverProvider)

	q, err := engine.LoadFile("qrc:///assets/main.qml")
	if err != nil {
		return err
	}

	window := q.CreateWindow(nil)
	c.Root = window.Root()
	c.Conv = cbconvert.NewConvertor(c.GetOptions())

	c.Root.On("closing", func(o qml.Object) {
		os.RemoveAll(c.Conv.Workdir)
	})

	c.Root.ObjectByName("buttonConvert").On("clicked", c.Convert)
	c.Root.ObjectByName("buttonCover").On("clicked", c.Cover)
	c.Root.ObjectByName("buttonThumbnail").On("clicked", c.Thumbnail)

	// center window
	x := c.Root.Int("screenWidth")/2 - c.Root.Int("width")/2
	y := c.Root.Int("screenHeight")/2 - c.Root.Int("height")/2
	window.Set("x", x)
	window.Set("y", y)

	window.Show()
	window.Wait()
	return nil
}