public RenderingQueueWindow(RenderingQueue renderingQueue)
            : base(WindowType.Toplevel)
        {
            this.Build ();

            title_Label.ModifyFont(FontHelpers.ScaleFontSize(title_Label, 1.4));

            // Adding queue event handlers
            mRenderingQueue = renderingQueue;
            mRenderingQueue.QueueProgressMessageReport += HandleRenderingQueueProgressMessageReport;
            mRenderingQueue.ItemAdded += HandleRenderingQueueItemAdded;
            mRenderingQueue.ItemIndexChanged += HandleRenderingQueueItemIndexChanged;
            mRenderingQueue.ItemRemoved += HandleRenderingQueueItemRemoved;
            mRenderingQueue.BeforeItemProcessingStarted += HandleRenderingQueueBeforeItemProcessingStarted;
            mRenderingQueue.AfterItemProcessingFinished += HandleRenderingQueueAfterItemProcessingFinished;
            mRenderingQueue.ThreadStarted += HandleRenderingQueueThreadStarted;
            mRenderingQueue.ThreadStopped += HandleRenderingQueueThreadStopped;
            mRenderingQueue.QueueEmpty += HandleRenderingQueueQueueEmpty;
            mRenderingQueue.ItemRendering += HandleRenderingQueueItemRendering;

            // Creating status icon

            string icon_res;
            if (System.Environment.OSVersion.Platform == PlatformID.Unix)
                icon_res = "CatEye.UI.Gtk.res.svg-inkscape.cateye-small.svg";
            else
            {
                // Windows, I hope.
                icon_res = "CatEye.UI.Gtk.res.png.cateye-small-16x16.png";
            }

            mProcessingStatusIcon = new StatusIcon(Gdk.Pixbuf.LoadFromResource(icon_res));
            mProcessingStatusIcon.Visible = false;	// In Windows status icon appears visible by default
            mProcessingStatusIcon.Activate += HandleProcessingStatusIconActivate;

            // Preparing queue list
            mQueueNodeStore = new NodeStore(typeof(RenderingTaskTreeNode));
            queue_nodeview.NodeStore = mQueueNodeStore;

            queue_nodeview.AppendColumn("Source", new CellRendererText(), "text", 0);
            queue_nodeview.AppendColumn("Destination", new CellRendererText(), "text", 1);

            expander1.Expanded = false;
            queue_GtkLabel.Markup = "<b>Queue (" + mRenderingQueue.Queue.Length + " left)</b>";
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            // Initializing remote control
            mRemoteControlService = new RemoteControlService("localhost", 21985);
            mRemoteControlService.RemoteCommandReceived += HandleRemoteControlServiceRemoteCommandReceived;

            // Parsing command line. Formulating command and it's arguments
            List<string> argslist = new List<string>(args);

            List<string> commands = new List<string>();
            List<List<string>> commands_arguments = new List<List<string>>();

            if (argslist.Contains("-q") || argslist.Contains("--queue"))
            {
                argslist.Remove("-q"); argslist.Remove("--queue");
                // Queue launch mode

                // Searching for "--default" option
                int d_inx = -1;
                d_inx = argslist.IndexOf("-d") >= 0 ? argslist.IndexOf("-d") : d_inx;
                d_inx = argslist.IndexOf("--default") >= 0 ? argslist.IndexOf("--default") : d_inx;
                string d_cestage_name = "";

                if (d_inx >= 0)
                {
                    if (d_inx < argslist.Count - 1)
                    {
                        d_cestage_name = argslist[d_inx + 1];
                        // Removing readed "-d"
                        argslist.RemoveRange(d_inx, 2);

                        if (!ReceiptsManager.IsReceipt(d_cestage_name))
                        {
                            Console.WriteLine("Incorrect argument: " + d_cestage_name + " is not a .cestage file.");
                            d_cestage_name = "";
                        }

                    } else if (d_inx == argslist.Count - 1)
                    {
                        Console.WriteLine("Incorrect argument: .cestage file name should be provided after --default or -d");
                        argslist.RemoveAt(d_inx);
                    }
                }

                // Searching for "--target-type"
                int tt_inx = -1;
                tt_inx = argslist.IndexOf("-t") >= 0 ? argslist.IndexOf("-t") : tt_inx;
                tt_inx = argslist.IndexOf("--target-type") >= 0 ? argslist.IndexOf("--target-type") : tt_inx;
                string target_type = "";

                if (tt_inx >= 0)
                {
                    if (tt_inx < argslist.Count - 1)
                    {
                        target_type = argslist[tt_inx + 1];
                        // Removing readed "-t"
                        argslist.RemoveRange(tt_inx, 2);

                        if (target_type != "jpeg" && target_type != "png" && target_type != "bmp")
                        {
                            Console.WriteLine("Incorrect target type specified: " + target_type + ". It should be \"jpeg\", \"png\" or \"bmp\".");
                            target_type = "";
                        }

                    } else if (tt_inx == argslist.Count - 1)
                    {
                        Console.WriteLine("Incorrect argument: target type should be provided after --target-type or -t");
                        argslist.RemoveAt(tt_inx);
                    }
                }

                // Searching for "--prescale"
                int p_inx = -1;
                p_inx = argslist.IndexOf("-p") >= 0 ? argslist.IndexOf("-p") : p_inx;
                p_inx = argslist.IndexOf("--prescale") >= 0 ? argslist.IndexOf("--prescale") : p_inx;
                int prescale = 2;

                if (p_inx >= 0)
                {
                    if (p_inx < argslist.Count - 1)
                    {
                        if (!int.TryParse(argslist[p_inx + 1], out prescale) || prescale < 1 || prescale > 8)
                        {
                            Console.WriteLine("Incorrect prescale value specified: " + argslist[p_inx + 1] + ". It should be an integer value from 1 to 8.");
                        }

                        // Removing readed "-t"
                        argslist.RemoveRange(p_inx, 2);

                    } else if (p_inx == argslist.Count - 1)
                    {
                        Console.WriteLine("Incorrect argument: prescale should be provided after --prescale or -p");
                        argslist.RemoveAt(p_inx);
                    }
                }

                // Now when all the additional parameters are parsed and removed,
                // we're analysing, what's left. The options:
                if (argslist.Count == 2 && ((ReceiptsManager.IsReceipt(argslist[0]) && RawLoader.IsRaw(argslist[1])) ||
                                           (ReceiptsManager.IsReceipt(argslist[1]) && RawLoader.IsRaw(argslist[0]))))
                {
                    // Two file names: one cestage and one raw

                    string cestage_filename;
                    string raw_filename;
                    if (ReceiptsManager.IsReceipt(argslist[0]) && RawLoader.IsRaw(argslist[1]))
                    {
                        cestage_filename = argslist[0];
                        raw_filename = argslist[1];
                    }
                    else // if (IsCEStageFile(argslist[1]) && DCRawConnection.IsRaw(argslist[0]))
                    {
                        cestage_filename = argslist[1];
                        raw_filename = argslist[0];
                    }

                    // Guessing target filename
                    if (target_type == "") target_type = "jpeg";
                    string target_name = System.IO.Path.ChangeExtension(raw_filename, target_type);
                    target_name = CheckIfFileExistsAndAddIndex(target_name);

                    // Launching StageEditor with the cestage file and the raw file
                    commands.Add("AddToQueue");
                    commands_arguments.Add(new List<string>(new string[]
                    {
                        cestage_filename,
                        raw_filename,
                        target_name,
                        target_type,
                        prescale.ToString()
                    }));
                }
                else
                {
                    // Searching for cestage for each raw and for raws for each cestage
                    for (int i = 0; i < argslist.Count; i++)
                    {
                        if (RawLoader.IsRaw(argslist[i]))
                        {
                            // The current file is a raw

                            // Guessing target filename
                            if (target_type == "") target_type = "jpeg";
                            string target_name = System.IO.Path.ChangeExtension(argslist[i], target_type);
                            target_name = CheckIfFileExistsAndAddIndex(target_name);

                            string[] cestages = ReceiptsManager.FindReceiptsForRaw(argslist[i]);
                            if (cestages.Length > 0)
                            {
                                // At least one found

                                // Launching StageEditor with the cestage file and the raw file
                                commands.Add("AddToQueue");
                                commands_arguments.Add(new List<string>(new string[]
                                {
                                    cestages[0],
                                    argslist[i],
                                    target_name,
                                    target_type,
                                    prescale.ToString()
                                }));
                            }
                            else if (d_cestage_name != "")
                            {
                                // Nothing found, but default name is present
                                commands.Add("AddToQueue");
                                commands_arguments.Add(new List<string>(new string[]
                                {
                                    d_cestage_name,
                                    argslist[i],
                                    target_name,
                                    target_type,
                                    prescale.ToString()
                                }));
                            }
                            else
                            {
                                Console.WriteLine("Can't open " + argslist[i] + ": can't find it's .cestage file");
                            }
                        }
                        else if (ReceiptsManager.IsReceipt(argslist[i]))
                        {
                            // The current file is a cestage

                            // Guessing target filename
                            if (target_type == "") target_type = "jpeg";
                            string target_name = System.IO.Path.ChangeExtension(argslist[i], target_type);
                            target_name = CheckIfFileExistsAndAddIndex(target_name);

                            string[] raws = new string[] {};
                            try
                            {
                                raws = ReceiptsManager.FindRawsForReceipt(argslist[i]);
                            }
                            catch (System.IO.DirectoryNotFoundException dnfe)
                            {
                                Console.WriteLine("Error: " + dnfe.Message);
                            }
                            if (raws.Length > 0)
                            {
                                // At least one found

                                commands.Add("AddToQueue");
                                commands_arguments.Add(new List<string>(new string[]
                                {
                                    argslist[i],
                                    raws[0],
                                    target_name,
                                    target_type,
                                    prescale.ToString()
                                }));

                            }
                            else
                            {
                                Console.WriteLine("Can't open " + argslist[i] + ": can't find it's raw file");
                            }
                        }

                    }

                }

            }
            else
            {
                // Not a queue launch mode

                // If we don't have 1 cestage and 1 raw, let's open as many windows as possible.

                // But, at first, trying to find "--default" option
                int d_inx = -1;
                d_inx = argslist.IndexOf("-d") >= 0 ? argslist.IndexOf("-d") : d_inx;
                d_inx = argslist.IndexOf("--default") >= 0 ? argslist.IndexOf("--default") : d_inx;
                string d_cestage_name = "";

                if (d_inx >= 0)
                {
                    if (d_inx < argslist.Count - 1)
                    {
                        d_cestage_name = argslist[d_inx + 1];
                        // Removing readed "-d"
                        argslist.RemoveRange(d_inx, 2);

                        if (!ReceiptsManager.IsReceipt(d_cestage_name))
                        {
                            Console.WriteLine("Incorrect argument: " + d_cestage_name + " is not a .cestage file.");
                            d_cestage_name = "";
                        }

                    } else if (d_inx == argslist.Count - 1)
                    {
                        Console.WriteLine("Incorrect argument: .cestage file name should be provided after --default or -d");
                        argslist.RemoveAt(d_inx);
                    }
                }

                // Searching for "--prescale"
                int p_inx = -1;
                p_inx = argslist.IndexOf("-p") >= 0 ? argslist.IndexOf("-p") : p_inx;
                p_inx = argslist.IndexOf("--prescale") >= 0 ? argslist.IndexOf("--prescale") : p_inx;
                int prescale = 2;

                if (p_inx >= 0)
                {
                    if (p_inx < argslist.Count - 1)
                    {
                        if (!int.TryParse(argslist[p_inx + 1], out prescale) || prescale < 1 || prescale > 8)
                        {
                            Console.WriteLine("Incorrect prescale value specified: " + argslist[p_inx + 1] + ". It should be an integer value from 1 to 8.");
                        }

                        // Removing readed "-p"
                        argslist.RemoveRange(p_inx, 2);

                    } else if (p_inx == argslist.Count - 1)
                    {
                        Console.WriteLine("Incorrect argument: prescale should be provided after --prescale or -p");
                        argslist.RemoveAt(p_inx);
                    }
                }

                if (argslist.Count == 2 && ReceiptsManager.IsReceipt(argslist[0]) && RawLoader.IsRaw(argslist[1]))
                {
                    // Launching StageEditor with the cestage file and the raw file
                    commands.Add("StageEditor_CEStage_RAW");
                    commands_arguments.Add(new List<string>(new string[]
                    {
                        argslist[0],
                        argslist[1],
                        prescale.ToString()
                    }));
                }
                else
                if (argslist.Count == 2 && ReceiptsManager.IsReceipt(argslist[1]) && RawLoader.IsRaw(argslist[0]))
                {
                    // Launching StageEditor with the cestage file and the raw file
                    commands.Add("StageEditor_CEStage_RAW");
                    commands_arguments.Add(new List<string>(new string[]
                    {
                        argslist[1],
                        argslist[0],
                        prescale.ToString()
                    }));
                }
                else
                {
                    // Searching for cestage for each raw and for raws for each cestage
                    for (int i = 0; i < argslist.Count; i++)
                    {
                        if (RawLoader.IsRaw(argslist[i]))
                        {
                            // The current file is a raw

                            if (d_cestage_name != "")
                            {
                                // Nothing found, but default name is present
                                commands.Add("StageEditor_CEStage_RAW");
                                commands_arguments.Add(new List<string>(new string[]
                                {
                                    d_cestage_name,
                                    argslist[i],
                                    prescale.ToString()
                                }));
                            }
                            else
                            {
                                commands.Add("StageEditor_RAW");
                                commands_arguments.Add(new List<string>(new string[]
                                {
                                    argslist[i],
                                    prescale.ToString()
                                }));
                            }
                        }
                        else if (ReceiptsManager.IsReceipt(argslist[i]))
                        {
                            // The current file is a cestage

                            string[] raws = ReceiptsManager.FindRawsForReceipt(argslist[i]);
                            if (raws.Length > 0)
                            {
                                // At least one found
                                // Launching StageEditor with the cestage file and the raw file
                                commands.Add("StageEditor_CEStage_RAW");
                                commands_arguments.Add(new List<string>(new string[]
                                {
                                    argslist[i],
                                    raws[0],
                                    prescale.ToString()
                                }));
                            }
                            else if (raws.Length == 0)
                            {
                                Gtk.MessageDialog md = new Gtk.MessageDialog(
                                    null, DialogFlags.Modal,
                                    MessageType.Error, ButtonsType.Ok,
                                    false, "Can't find raw file for {0}", argslist[i]);

                                md.Title = MainClass.APP_NAME;

                                md.Run();
                                md.Destroy();
                            }
                            else // raws.Length > 1
                            {
                                Gtk.MessageDialog md = new Gtk.MessageDialog(
                                    null, DialogFlags.Modal,
                                    MessageType.Error, ButtonsType.Ok,
                                    false, "More than one raw file found for {0}", argslist[i]);

                                md.Title = MainClass.APP_NAME;

                                md.Run();
                                md.Destroy();
                            }
                        }

                    }
                }
            }

            bool ownServerStarted = mRemoteControlService.Start();

            if (ownServerStarted)
            {
                string mylocation = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetCallingAssembly().Location);
                windowsGtkStyle = new WindowsGtkStyle(mylocation +
                                                      Path.DirectorySeparatorChar +
                                                      "res" +
                                                      Path.DirectorySeparatorChar +
                                                      "win-gtkrc");
                Application.Init ();

                // Creating render queue and its window
                mRenderingQueue = new RenderingQueue();
                mRenderingQueueWindow = new RenderingQueueWindow(mRenderingQueue);
                mRenderingQueue.StartThread();
            }

            // No files asked
            if (commands.Count == 0)
            {
                // No command line arguments passed.
                // Sending the "StageEditor" command with no arguments
                commands.Add("StageEditor");
                commands_arguments.Add(new List<string>());
            }

            // Sending the commands
            List<string> packed_commands = new List<string>();
            for (int i = 0; i < commands.Count; i++)
            {
                packed_commands.Add(RemoteControlService.PackCommand(commands[i], commands_arguments[i].ToArray()));
            }
            mRemoteControlService.SendCommands(packed_commands.ToArray());

            if (ownServerStarted)
            {
                GLib.Idle.Add(delegate {
                    // Checking if something is already started
                    if (RenderingQueue.IsProcessingItem || StageEditorWindows.Count > 0)
                        mLoadedSomethingAlready = true;

                    // Removing all destroyed
                    StageEditorWindows.RemoveAll(delegate (StageEditorWindow wnd)
                    {
                        return wnd.IsDestroyed;
                    });

                    // Checking is there any activity or no
                    if (mLoadedSomethingAlready &&
                        StageEditorWindows.Count == 0 &&
                        !RenderingQueue.IsProcessingItem)
                    {
                        RenderingQueue.StopThread();
                        Application.Quit();
                    }
                    return true;
                });

                Application.Run();
            }
            mRemoteControlService.Stop();
        }