Beispiel #1
0
        public Form1()
        {
            InitializeComponent();
            try {
                username = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
            } catch {
                username = "******";
            }

            Jobs = new List<ListViewItem >();
            _jobs = new List<MusicJob>();

            ipTextBox.Text = Properties.Settings.Default.SpoolerIp;

            if (Properties.Settings.Default.SpoolerIp != "")
            {
                backgroundWorker1.RunWorkerAsync();
            }

            ActiveJob = null;
            OldActiveJob = new MusicJob("", "", "", "", "");

            ListView_SizeChanged(listView1, null);

            restore = new clientRect();

            this.Select();
            this.Focus();
        }
Beispiel #2
0
        private Boolean parseLpq()
        {
            Printer printer1 = new Printer(Properties.Settings.Default.SpoolerIp, "lp", username);
            if (!printer1.ErrorMsg.Equals(""))
            {
                notifyIcon1.ShowBalloonTip(2000, "Error while spooling", printer1.ErrorMsg, ToolTipIcon.Error);
                return false;
            }

            String lines = printer1.LPQ(false).Trim().Replace("\0", string.Empty);

            Boolean newElement = false;

            lock (Jobs)
            {
                MatchCollection matches = multiLine.Matches(lines);

                if (matches.Count != Jobs.Count())
                {
                    newElement = true;
                }

                Jobs = new List<ListViewItem>();
                _jobs = new List<MusicJob>();
                foreach (Match m in matches)
                {
                    String user = m.Result("${user}").Trim();
                    String status = m.Result("${status}").Trim();
                    String jobid = m.Result("${jobid}").Trim();
                    String details = m.Result("${details}").Trim();
                    String title = m.Result("${title}").Trim();
                    String size = m.Result("${size}").Trim();

                    ListViewItem item = new ListViewItem();
                    item.Tag = jobid;
                    int bytes = 0;
                    Int32.TryParse(size, out bytes);
                    item.Text = String.Format("{0,-8} {1,-15} {2,-6}MB {3}", status, user, ConvertIntToMegabytes(bytes).ToString("0.00"), title);
                    item.ImageIndex = 0;
                    Jobs.Add(item);
                    _jobs.Add(new MusicJob(user, status, details, title, size));
                }

            }

            List<MusicJob> activeJobs = _jobs.Where(a => a.status == "active").ToList<MusicJob>();

            if (activeJobs.Count() > 0)
            {
                if (ActiveJob == null || activeJobs.First().title != ActiveJob.title)
                {
                    notifyIcon1.ShowBalloonTip(2000, "Currently Playing", activeJobs.First().title, ToolTipIcon.Info);
                    ActiveJob = activeJobs.First();
                    newElement = true;
                }
            }
            else
            {
                ActiveJob = null;
            }
            return newElement;
        }
Beispiel #3
0
        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            lastUpdate.Text = "Last Update: " + System.DateTime.Now.ToString();
            tracksLbl.Text = "Tracks: " + Jobs.Count();

            if (e.ProgressPercentage == 100)
            {
                /*
                 * Save selected items for restore
                 */
                List <ListViewItem> _selected = new List<ListViewItem>();
                foreach (ListViewItem i in listView1.SelectedItems)
                {
                    _selected.Add(i);
                }
                /*
                 * Update the list
                 */
                listView1.Items.Clear();
                foreach (ListViewItem i in Jobs)
                {
                    listView1.Items.Add(i);
                }

                /*
                 * Restore selected items
                 */
                foreach (ListViewItem lvi in _selected)
                {
                    foreach (ListViewItem i in listView1.Items)
                    {
                        if ((string)lvi.Tag == (string)i.Tag)
                        {
                            i.Selected = true;
                        }
                    }
                }

                /*
                 * Update ScrollText
                 */
                if (ActiveJob == null)
                {
                    scrollingLbl.Text = "";
                }
                else if (ActiveJob.title != OldActiveJob.title)
                {
                    scrollingLbl.Text = ActiveJob.title;
                    OldActiveJob = ActiveJob;
                }
            }
        }