예제 #1
0
        public MainWindow()
        {
            InitializeComponent();

            App.ViewModel = new AppViewModel();
            DataContext   = App.ViewModel;

            WindowState = System.Windows.WindowState.Minimized;

            Loaded += (_, __) =>
            {
                if (!AppJumpList.RunningOnWin7)
                {
                    MessageBox.Show("This application requires Windows 7", "Windows 7 Required", MessageBoxButton.OK);
                    Environment.Exit(1);
                }

                Program.JumpList.SetJumpList();

                Program.JumpList.OtherCommandLineReceived += line =>
                {
                    // from explorer
                    Trace.WriteLine("CLI from explorer: " + line);

                    var list = new List <string>();
                    list.Add(line);
                    UploadFileList(list);
                };

                Program.SetMenu(true);

                if (Program.HTTP == null)
                {
                    FlashProgress(TaskbarProgressBarState.Error);
                }
            };

            Closing += (_, e) =>
            {
                WindowState = System.Windows.WindowState.Minimized;
                e.Cancel    = true;
            };

            Program.JumpListItemClicked += item =>
            {
                this.Invoke(() =>
                {
                    Window w = null;
                    switch (item.Title)
                    {
                    case "Send Note":
                        w = new NoteWindow();
                        break;

                    case "Send SMS":
                        w = new MessageWindow(MessageWindowType.SMS);
                        break;

                    case "Send Mail":
                        w = new MessageWindow(MessageWindowType.EMail);
                        break;

                    case "Send Clipboard":
                        SendClipboard();
                        break;

                    case "Set Transfer Destination":
                        Uploader.PresentOptions(() => {
                            FlashProgress(TaskbarProgressBarState.Normal);
                        }, () => {
                            FlashProgress(TaskbarProgressBarState.Paused);
                        }, IntPtr.Zero);
                        break;

                    default:
                        Trace.WriteLine("Invalid jumplist item: " + item);
                        break;
                    }
                    if (w != null)
                    {
                        w.Show();
                        w.Topmost = true;
                        w.Activate();
                        this.InvokeDelay(1000, () => w.Topmost = false);
                    }
                });
            };
        }
예제 #2
0
        private void SendClipboard()
        {
            if (Clipboard.ContainsText())
            {
                var clipText = Clipboard.GetText();
                TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.Indeterminate);
                new Thread(() =>
                {
                    App.ViewModel.API.SendMessage("clip", "Clipboard Text", "", clipText);
                    FlashProgress(TaskbarProgressBarState.Normal);
                }).Start();
            }
            else if (Clipboard.ContainsImage())
            {
                try
                {
                    TaskbarManager.Instance.SetProgressState(TaskbarProgressBarState.Indeterminate);

                    var    clipimg = Clipboard.GetImage();
                    string path    = System.IO.Path.Combine(System.IO.Path.GetTempPath(),
                                                            "S2WP7_" + new Random().Next(0, int.MaxValue) + "_Clipboard");

                    if (Settings.Get("Clipboard_PNG", true))
                    {
                        path += ".png";
                    }
                    else
                    {
                        path += ".jpg";
                    }

                    using (FileStream stream = new FileStream(path, FileMode.Create))
                    {
                        BitmapEncoder encoder;
                        if (Settings.Get("Clipboard_PNG", true))
                        {
                            encoder = new PngBitmapEncoder();
                            (encoder as PngBitmapEncoder).Interlace = PngInterlaceOption.On;
                        }
                        else
                        {
                            encoder = new JpegBitmapEncoder();
                            (encoder as JpegBitmapEncoder).QualityLevel = Settings.Get("JpegQuality", 95);
                        }
                        encoder.Frames.Add(BitmapFrame.Create(clipimg));
                        encoder.Save(stream);
                    }
                    Trace.WriteLine("Image saved at: " + path);

                    var t = new Thread(() =>
                    {
                        try
                        {
                            Uploader.UploadFile(path, ret =>
                            {
                                if (ret.URL == null)
                                {
                                    Trace.WriteLine("*** URL is null");
                                    FlashProgress(TaskbarProgressBarState.Error);
                                }
                                else
                                {
                                    App.ViewModel.API.SendMessage("img", "Clipboard Image", ret.URL, "");
                                    FlashProgress(TaskbarProgressBarState.Normal);
                                }
                            }, () =>
                            {
                                FlashProgress(TaskbarProgressBarState.Paused);
                            });
                        }
                        catch (Exception ex)
                        {
                            FlashProgress(TaskbarProgressBarState.Error);
                            Trace.WriteLine("Error uploading file: " + ex);
                        }
                    });
                    t.SetApartmentState(ApartmentState.STA);
                    t.Start();
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("Error saving image:" + ex);
                }
            }
            else if (Clipboard.ContainsFileDropList())
            {
                UploadFileList(GetFilesFromDropList(Clipboard.GetFileDropList()));
            }
            else
            {
                FlashProgress(TaskbarProgressBarState.Error);
                Trace.WriteLine("Clipboard content is not valid");
            }
        }