Example #1
0
        public override IEnumerable <Item> Perform(IEnumerable <Item> items, IEnumerable <Item> modifierItems)
        {
            RTMTaskItem   task      = null;
            List <string> temp_tags = new List <string> ();

            if (items.Any())
            {
                if (items.First() is RTMTaskItem)
                {
                    task = (items.First() as RTMTaskItem);
                }
                else if (items.First() is RTMTaskAttributeItem)
                {
                    task = (items.First() as RTMTaskAttributeItem).Parent;
                }
            }

            if (modifierItems.Any() && task != null)
            {
                foreach (Item item in modifierItems)
                {
                    temp_tags.Add((item as RTMTagItem).Name);
                }

                Services.Application.RunOnThread(() => {
                    RTM.DeleteTags(task.ListId, task.TaskSeriesId,
                                   task.Id, String.Join(",", temp_tags.ToArray()));
                });
            }
            yield break;
        }
Example #2
0
        public override IEnumerable <Item> Perform(IEnumerable <Item> items, IEnumerable <Item> modifierItems)
        {
            RTMTaskItem task = null;
            string      due  = String.Empty;

            if (items.Any())
            {
                if (items.First() is RTMTaskItem)
                {
                    task = (items.First() as RTMTaskItem);
                }
                else if (items.First() is RTMTaskAttributeItem)
                {
                    task = (items.First() as RTMTaskAttributeItem).Parent;
                }
            }

            if (modifierItems.Any())
            {
                due = (modifierItems.First() as ITextItem).Text;
            }

            if (task != null)
            {
                Services.Application.RunOnThread(() => {
                    RTM.SetDueDateTime(task.ListId, task.TaskSeriesId, task.Id, due);
                });
            }

            yield break;
        }
Example #3
0
 public RTMTaskAttributeItem(string name, string description, string url, string icon, RTMTaskItem parent)
 {
     this.name        = name;
     this.description = description;
     this.url         = url;
     this.icon        = icon;
     this.parent      = parent;
 }
Example #4
0
        public override IEnumerable <Item> Perform(IEnumerable <Item> items, IEnumerable <Item> modifierItems)
        {
            RTMTaskItem task = null;
            string      url  = String.Empty;

            if (items.Any())
            {
                if (items.First() is RTMTaskItem)
                {
                    task = (items.First() as RTMTaskItem);
                }
                else if (items.First() is RTMTaskAttributeItem)
                {
                    task = (items.First() as RTMTaskAttributeItem).Parent;
                }
            }

            if (modifierItems.FirstOrDefault() != null)
            {
                url = ((modifierItems.FirstOrDefault() as ITextItem).Text);
            }

            // User may have entered explicit mode and entered a blank line.
            // To be safe; strip out all new line characters from input
            // for URL resetting.
            url = url.Replace("\n", "");

            // The URL set to the task may be reset if the entered text is empty.
            // Check if it's not empty.
            if (!string.IsNullOrEmpty(url))
            {
                // Check if the entered text is a valid URL.
                if (!CheckValidURL(url))
                {
                    // Error in entered URL.
                    Services.Notifications.Notify("Remember The Milk",
                                                  AddinManager.CurrentLocalizer.GetString("Invalid URL provided."));
                    yield break;
                }
            }

            if (task != null)
            {
                Services.Application.RunOnThread(() => {
                    RTM.SetURL(task.ListId, task.TaskSeriesId, task.Id, url);
                });
            }
            yield break;
        }
Example #5
0
        /// <summary>
        /// Generates all <see cref="RTMTaskAttributeItem"/>s based on the available properties of a task.
        /// </summary>
        /// <param name="task">
        /// A <see cref="RTMTaskItem"/> indicating the task.
        /// </param>
        /// <returns>
        /// A <see cref="List"/> of <see cref="Item"/> containing the generated attributes.
        /// </returns>
        public static List <Item> AttributesForTask(RTMTaskItem task)
        {
            List <Item> attribute_list = new List <Item> ();

            if (task.Due != DateTime.MinValue)
            {
                attribute_list.Add(new RTMTaskAttributeItem(task.Due.ToString((task.HasDueTime != 0) ? "g" : "d"),
                                                            "Due Date/Time", task.Url, "stock_calendar", task));
            }

            if (!String.IsNullOrEmpty(task.TaskUrl))
            {
                attribute_list.Add(new RTMTaskAttributeItem(task.TaskUrl, "URL", task.TaskUrl, "text-html", task));
            }

            if (!String.IsNullOrEmpty(task.Estimate))
            {
                attribute_list.Add(new RTMTaskAttributeItem(task.Estimate, "Time Estimate",
                                                            task.Url, "stock_appointment-reminder", task));
            }

            if (!String.IsNullOrEmpty(task.LocationId))
            {
                attribute_list.Add(locations.Find(i => (i as RTMLocationItem).Id == task.LocationId));
            }

            if (!String.IsNullOrEmpty(task.Tags))
            {
                attribute_list.Add(new RTMTaskAttributeItem(task.Tags, "Tags", task.Url,
                                                            "task-tag.png@" + typeof(RTMListItemSource).Assembly.FullName, task));
            }

            List <Item> note_list = notes.FindAll(i => (i as RTMNoteItem).TaskId == task.Id);

            if (note_list.Any())
            {
                lock (note_lock) {
                    foreach (Item item in note_list)
                    {
                        attribute_list.Add(item);
                    }
                }
            }
            return(attribute_list);
        }
Example #6
0
        public override IEnumerable <Item> Perform(IEnumerable <Item> items, IEnumerable <Item> modifierItems)
        {
            RTMTaskItem task = null;
            string      est  = String.Empty;

            if (items.Any())
            {
                if (items.First() is RTMTaskItem)
                {
                    task = (items.First() as RTMTaskItem);
                }
                else if (items.First() is RTMTaskAttributeItem)
                {
                    task = (items.First() as RTMTaskAttributeItem).Parent;
                }
            }

            if (modifierItems.Any())
            {
                est = ((modifierItems.First() as ITextItem).Text);
            }

            if (!string.IsNullOrEmpty(est))
            {
                if (!CheckValidTime(est))
                {
                    Services.Notifications.Notify(AddinManager.CurrentLocalizer.GetString("Invalid Time format"),
                                                  AddinManager.CurrentLocalizer.GetString("The estimated time entered cannot be understood."),
                                                  "rtm.png@" + GetType().Assembly.FullName);
                    yield break;
                }
            }

            if (task != null)
            {
                Services.Application.RunOnThread(() => {
                    RTM.SetEstimateTime(task.ListId, task.TaskSeriesId, task.Id, est);
                });
            }

            yield break;
        }
Example #7
0
        public override IEnumerable <Item> Perform(IEnumerable <Item> items, IEnumerable <Item> modifierItems)
        {
            RTMTaskItem   task      = null;
            List <string> temp_tags = new List <string> ();
            string        s         = null;

            if (items.Any())
            {
                if (items.First() is RTMTaskItem)
                {
                    task = (items.First() as RTMTaskItem);
                }
                else if (items.First() is RTMTaskAttributeItem)
                {
                    task = (items.First() as RTMTaskAttributeItem).Parent;
                }
            }

            if (modifierItems.Any() && task != null)
            {
                foreach (Item item in modifierItems)
                {
                    s = GetText(item);
                    if (!String.IsNullOrEmpty(s))
                    {
                        temp_tags.Add(s);
                    }
                }

                Services.Application.RunOnThread(() => {
                    RTM.AddTags((items.First() as RTMTaskItem).ListId, (items.First() as RTMTaskItem).TaskSeriesId,
                                (items.First() as RTMTaskItem).Id, String.Join(",", temp_tags.ToArray()));
                });
            }
            yield break;
        }
Example #8
0
 public RTMTaskAttributeItem(string name, string description, string url, RTMTaskItem parent) :
     this(name, description, url, "rtm.png@", parent)
 {
 }
Example #9
0
        /// <summary>
        /// Updates the list of tasks as <see cref="RTMTaskItem"/>s from the RTM server.
        /// Also collects all the notes and tags during the update.
        /// </summary>
        public static void UpdateTasks()
        {
            lock (task_lock) {
                if (!IsAuthenticated && !TryConnect())
                {
                    return;
                }

                Tasks rtmTasks;
                Tasks rtmTasks_sync;

                if (last_sync == DateTime.MinValue)
                {
                    tasks.Clear();
                    tags.Clear();
                    notes.Clear();
                }

                try {
                    // If first time sync, get full list of tasks restricted by filter
                    // otherwise, only do incremental sync.
                    if (last_sync == DateTime.MinValue)
                    {
                        rtmTasks      = rtm.TasksGetList(null, null, filter);
                        rtmTasks_sync = null;
                    }
                    else
                    {
                        rtmTasks_sync = rtm.TasksGetList(null, last_sync.ToUniversalTime().ToString("u"), null);
                        rtmTasks      = rtm.TasksGetList(null, last_sync.ToUniversalTime().ToString("u"), filter);
                    }
                } catch (RtmException e) {
                    rtmTasks      = null;
                    rtmTasks_sync = null;
                    last_sync     = DateTime.MinValue;
                    Log <RTM> .Debug(AddinManager.CurrentLocalizer.GetString("An error occured when updating RTM tasks: {0}"),
                                     e.Message);

                    return;
                }

                // if not first time sync, delete all changed tasks (using the list with nothing filtered)
                if (last_sync != DateTime.MinValue)
                {
                    foreach (List rtmList in rtmTasks_sync.ListCollection)
                    {
                        if (rtmList.DeletedTaskSeries != null)
                        {
                            foreach (TaskSeries rtmTaskSeries in rtmList.DeletedTaskSeries.TaskSeriesCollection)
                            {
                                foreach (Task rtmTask in rtmTaskSeries.TaskCollection)
                                {
                                    TryRemoveTask(rtmTask.TaskID);
                                }
                            }
                        }

                        if (rtmList.TaskSeriesCollection != null)
                        {
                            foreach (TaskSeries rtmTaskSeries in rtmList.TaskSeriesCollection)
                            {
                                foreach (Task rtmTask in rtmTaskSeries.TaskCollection)
                                {
                                    TryRemoveTask(rtmTask.TaskID);
                                }
                            }
                        }
                    }
                }

                // add changed tasks from the list with filter used.
                foreach (List rtmList in rtmTasks.ListCollection)
                {
                    if (rtmList.TaskSeriesCollection != null)
                    {
                        foreach (TaskSeries rtmTaskSeries in rtmList.TaskSeriesCollection)
                        {
                            foreach (Task rtmTask in rtmTaskSeries.TaskCollection)
                            {
                                // delete one recurrent task will cause other deleted instances
                                // appear in the taskseries tag, so here we need to check again.
                                if (rtmTask.Deleted == DateTime.MinValue)
                                {
                                    // handle tags
                                    string temp_tags = "";
                                    if (rtmTaskSeries.Tags.TagCollection.Length > 0)
                                    {
                                        foreach (Tag rtmTag in rtmTaskSeries.Tags.TagCollection)
                                        {
                                            if (tags.FindIndex(i => (i as RTMTagItem).Name == rtmTag.Text) == -1)
                                            {
                                                tags.Add(new RTMTagItem(rtmTag.Text));
                                            }
                                            temp_tags += rtmTag.Text + ", ";
                                        }
                                        temp_tags = temp_tags.Remove(temp_tags.Length - 2);
                                    }

                                    // handle notes
                                    if (rtmTaskSeries.Notes.NoteCollection.Length > 0)
                                    {
                                        foreach (Note rtmNote in rtmTaskSeries.Notes.NoteCollection)
                                        {
                                            notes.Add(new RTMNoteItem(rtmNote.Title, rtmNote.Text, rtmNote.ID,
                                                                      String.Format("http://www.rememberthemilk.com/print/{0}/{1}/{2}/notes/",
                                                                                    username, rtmList.ID, rtmTask.TaskID), rtmTask.TaskID));
                                        }
                                    }

                                    // add new task
                                    RTMTaskItem new_task = new RTMTaskItem(rtmList.ID, rtmTaskSeries.TaskSeriesID,
                                                                           rtmTask.TaskID, rtmTaskSeries.Name, rtmTask.Due, rtmTask.Completed,
                                                                           rtmTaskSeries.TaskURL, rtmTask.Priority, rtmTask.HasDueTime,
                                                                           rtmTask.Estimate, rtmTaskSeries.LocationID, temp_tags);
                                    tasks.Add(new_task);
                                }
                            }
                        }
                    }
                }
                last_sync = DateTime.Now;
            }

            Log <RTM> .Debug("Received {0} tasks.", tasks.ToArray().Length);

            Log <RTM> .Debug("Received {0} notes.", notes.ToArray().Length);

            Log <RTM> .Debug("Received {0} tags.", tags.ToArray().Length);
        }
Example #10
0
 /// <summary>
 /// Check if a task is due in next 7 days.
 /// </summary>
 /// <param name="item">
 /// A <see cref="RTMTaskItem"/> indicating the task to be checked.
 /// </param>
 /// <returns>
 /// Ignored
 /// </returns>
 static bool IsDueInAWeek(RTMTaskItem item)
 {
     return(item.Completed == DateTime.MinValue && item.Due != DateTime.MinValue &&
            item.Due.Date <= DateTime.Today.AddDays(6.0));
 }
Example #11
0
 /// <summary>
 /// Check if a task is due tomorrow
 /// </summary>
 /// <param name="item">
 /// A <see cref="RTMTaskItem"/> indicating the task to be checked
 /// </param>
 /// <returns>
 /// Ignored
 /// </returns>
 static bool IsDueTomorrow(RTMTaskItem item)
 {
     return(item.Completed == DateTime.MinValue && item.Due.Date == DateTime.Today.AddDays(1.0));
 }
Example #12
0
 /// <summary>
 /// Check if a task is due today
 /// </summary>
 /// <param name="item">
 /// A <see cref="RTMTaskItem"/> indicating the task to be checked
 /// </param>
 /// <returns>
 /// Ignored
 /// </returns>
 static bool IsDueToday(RTMTaskItem item)
 {
     return(item.Completed == DateTime.MinValue && item.Due.Date == DateTime.Today);
 }
Example #13
0
 /// <summary>
 /// Check if a task is overdue.
 /// </summary>
 /// <param name="item">
 /// A <see cref="RTMTaskItem"/> indicating the task to be checked.
 /// </param>
 /// <returns>
 /// Ignored
 /// </returns>
 static bool IsOverdue(RTMTaskItem item)
 {
     return(item.Completed == DateTime.MinValue && item.Due > DateTime.MinValue &&
            ((item.HasDueTime == 1 && item.Due < DateTime.Now) || item.Due.Date < DateTime.Today));
 }