~cszikszoy/do-plugins/fix-confluence

« back to all changes in this revision

Viewing changes to Quote/src/QuoteAction.cs

  • Committer: Alex Launi
  • Date: 2009-01-06 07:11:16 UTC
  • mto: (407.1.4 trunk)
  • mto: This revision was merged to the branch mainline in revision 409.
  • Revision ID: alex.launi@gmail.com-20090106071116-62bb3zeds067vk2i
Finish first draft of quoting plugin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* QuoteAction.cs 
 
2
 *
 
3
 * GNOME Do is the legal property of its developers. Please refer to the
 
4
 * COPYRIGHT file distributed with this
 
5
 * source distribution.
 
6
 *
 
7
 * This program is free software: you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation, either version 3 of the License, or
 
10
 * (at your option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
 */
 
20
 
 
21
using System;
 
22
using System.IO;
 
23
using System.Net;
 
24
using System.Text;
 
25
using System.Linq;
 
26
using System.Collections.Generic;
 
27
using System.Text.RegularExpressions;
 
28
 
 
29
using Do.Platform;
 
30
using Do.Universe;
 
31
using Do.Universe.Common;
 
32
 
 
33
using Mono.Unix;
 
34
 
 
35
namespace Quote
 
36
{
 
37
        public class PostQuote : Act
 
38
        {
 
39
                public override string Name {
 
40
                        get { return Catalog.GetString ("Submit Quote"); }
 
41
                }
 
42
                
 
43
                public override string Description {
 
44
                        get { return Catalog.GetString ("Sends text to Quote service."); }
 
45
                }
 
46
                
 
47
                public override string Icon {
 
48
                        get { return "gtk-paste"; }
 
49
                }
 
50
                
 
51
                public override IEnumerable<Type> SupportedItemTypes {
 
52
                        get {
 
53
                                yield return typeof (ITextItem);
 
54
                        }
 
55
                }
 
56
                        
 
57
                public override bool ModifierItemsOptional  {
 
58
                        get { return true; }
 
59
                }
 
60
                
 
61
                public override IEnumerable<Type> SupportedModifierItemTypes
 
62
                {
 
63
                        get { yield return typeof (ITextItem); }
 
64
                }
 
65
                        
 
66
                public override IEnumerable<Item> DynamicModifierItemsForItem (Item item)
 
67
                {
 
68
                        IQuoteProvider quoteProvider = QuoteProviderFactory.GetProviderFromPreferences ();
 
69
                        return quoteProvider.SavedTags.OfType<Item> ();
 
70
                }
 
71
                                
 
72
                public override IEnumerable<Item> Perform (IEnumerable<Item> items, IEnumerable<Item> modifierItems)
 
73
                {
 
74
                        ITextItem titem = null;
 
75
                        string text = string.Empty;
 
76
                        
 
77
                        
 
78
                        foreach (Item item in items) {
 
79
                                titem = new TextItem ((item as ITextItem).Text);
 
80
                                text += titem.Text;
 
81
                        }
 
82
                        
 
83
                        IQuoteProvider quoteProvider = null;
 
84
                                        
 
85
                        if (modifierItems.Any ()) {
 
86
                                quoteProvider = QuoteProviderFactory.GetProviderFromPreferences (text, (modifierItems.First () as ITextItem).Text);
 
87
                        } else {
 
88
                                quoteProvider = QuoteProviderFactory.GetProviderFromPreferences (text);         
 
89
                        }
 
90
                                        
 
91
                        string url = Quote.PostUsing (quoteProvider);   
 
92
                                        
 
93
                        yield return new TextItem (url);
 
94
                }
 
95
        }
 
96
}
 
97
 
 
98