Archive for April, 2007

www.youtube.com Or youtube.com? That is the question…

Recently I’ve been getting a lot of support emails for my video plugin from people who are having troubles inserting a video using my plugin, when I’ve subsequently asked them for the video link so that I can give it a go as well, I find that they haven’t really taken note of what I said when I first released my video plugin way back when. And to be fair to them, why should they, I posted it back in September (or something like that), and what’s more, on a different blog. and I’ve never really repeated those instructions, not when version 2 was released and not when version 3 got released, so I can’t blame people for not doing what I originally said.

The original instructions were to take the link from the "share" part of whatever video website you are getting the video from, and not the address bar, for the main reason that I was using those links to validate the video. So what people have been doing is, instead of putting in a video with www.youtube.com in the url, they have been putting youtube.com and so my plugin has been giving them an error and saying it’s not a valid url, even though it clearly was. It has always been my intention to change this and make it work regardless of the www. or not, and in hindsight, I should have put this in the original release of V3, but in all honesty, I forgot!

So, now I have updated the video plugin (v3.0.1) so it doesn’t matter whether your video url has www. or not, for any of the supported video sites, and as always is available to download from Live Gallery.

One final thing, I have noticed that due to the changes in policy at the moment from the Soapbox team, using the feature that puts the video name underneath the video will always return "Soapbox on MSN Video Beta", this is because the site now requires you to log in to actually get any information other than the embedding of the video. There is simply no workaround for this, sorry.

SL

 
Whilst writing this I was listening to Foo FightersWhat If I Do?

4 Comments

Writing Plugins For Windows Live Writer – Using Settings In Your Plugin

So far I’ve shown you how to create basic plugins for Windows Live Writer, in this next guide I’m going to show you how you can use settings in your plugin to make things easier for your end user, you can create default options (that they can customise if you allow them). I’m going to show you how to do exactly that, have the user be able to change the default settings that are applied everytime the plugin is called. I will be carrying this on from my last guide so if you haven’t got that already, download the source now.

First thing’s first, what options does your plugin need? This is still going to be a simple plugin, so anything you put in can’t be changed once inserted, so the options and settings need to be something that the user would want. The simple plugin we have been using so far in this series has been to insert some simple text into the blog entry, so the option I’m going to use is to make it default to use a bold style for the text.

For the settings, we need to create a new Class that will contain all the settings’ properties. In this example, I have called it PluginSettings.cs. Before we call the constructor, we need to just declare an instance of the IProperties Interface: 

        private IProperties m_properties;
        private const string DEFAULTBOLD = "DEFAULTBOLD";

At this point, I also like to declare constants for the setting properties, these will be used in a bit, I will note that you don’t need to put these in, this is more a personal preference for me.

The settings class needs to be passed an IProperties instance so that it has a point of reference, then you need to set the IProperties instance you just declared to be the one that gets passed to the class. So your constructor should look like this: 

        public PluginSettings(IProperties properties)
        {
            m_properties = properties;
        }

Next we write the properties for the settings class, you will need one of these for each of the settings you use in your plugin and they can be one of five different types: int, string, boolean, decimal or float. For this plugin, I’m going to use a boolean type as I want it to either be yes (true) or no (false) for whether the text should be bold or not. This plugin only requires one property, and mine looks like this:  

        public bool DefaultBoldOption
        {
            get { return m_properties.GetBoolean(DEFAULTBOLD, true); }
            set { m_properties.SetBoolean(DEFAULTBOLD, value); }
        }

You’ll see that this is where we used the constant value I mentioned earlier, this is the property name that tells the plugin which setting to get, and you’ll see that there are two sections, a get section, and a set section. The get section must return a value of whatever type you’re using, in this case, a boolean value, so we use the IProperties’ GetBoolean method and put in the property name that we want. The set section is where we assign what the property’s value is going to be. This will all become clearer a bit further on. And that’s the settings class done with.

Now we move back to the plugin’s main class. To start off with, declare a PluginSettings object (I’ve called it m_defaultoptions), this will be set next. To do this, we need to override the Initialize method so that we can get the IProperties object for that plugin. Declaring the settings originally outside of this method means that the default options are available to the rest of the plugin. It should look like this: 

        public override void Initialize(IProperties pluginOptions)
        {
            base.Initialize(pluginOptions);
            m_defaultsettings = new PluginSettings(pluginOptions);
        }

Notice how we pass the PluginSettings class the IProperties object so that it knows where it’s reading/writing from.

You might remember in the previous parts to this guide, in the WriterPlugin section we had HasEditbleOptions set to false, well now we’re going to set it to true, this will enable the Options button in the plugins part of the preferences. Before we tell the plugin about the options window, let’s create the form first. So add a new Windows form to the project (I called mine frmOptions.cs) and make your form look something like this:

Now, hit F7 and go into the code for the form and you will need to add the using WindowsLive.Writer.Api; namespace again. At the top, declare a new instance of the PluginSettings class, and in the constructor we need to then set that to be the PluginSettings that is being passed to the form, then apply the default settings. So your code should look like this:

        public frmOptions(PluginSettings settings)
        {
            InitializeComponent();
            m_settings = settings;
            // This sets the checkbox to be whatever the default option was
            chBoldOption.Checked = m_settings.DefaultBoldOption;
        }

Now these settings are only basic, so when we press the save button, there’s only one setting that needs to be saved, which we do with the following line:

        private void btnSave_Click(object sender, EventArgs e)
        {
            // This actually sets the option to be whatever the checkbox is currently at
            m_settings.DefaultBoldOption = chBoldOption.Checked;
            this.Close();
        }

Right, back to the main plugin class. Now that we have our options form, we need to tell the plugin what to do when the options button is pressed; so we need to override the EditOptions method. In this method, we are literally just going to create a new instance of the PluginSettings and use the stored options for that plugin, then pass that to the form, as follows:

        public override void EditOptions(IWin32Window dialogOwner)
        {
            PluginSettings options = new PluginSettings(this.Options);
            frmOptions op = new frmOptions(options);
            op.ShowDialog();
        }

Now, the final thing to do is actually apply these settings to the text that is put into the blog entry. For this plugin, this is simple as there is only one setting. So in the CreateContent method, we had the if statement to say that if (result == DialogResult.OK) then we make newContent = form.getText. All we will do for this plugin is add an extra if statement after that which checks whether the setting is to be applied or not, and as we have made this setting a boolean value, it makes it even easier to check. So the if statement we want is basically this:

                    if (m_defaultsettings.DefaultBoldOption)
                        newContent = string.Format("<b>{0}</b>", newContent);

And that’s it, you should be done

As always, the source code that I have used can be downloaded here.

Any problems, please leave a comment.

SL

10 Comments

Featured Plugins On Live Gallery

Noticed that two of my plugins, the Video and Emoticon ones, are the featured plugins on Live Gallery under the Live Writer section

SL 

9 Comments

Slight Bug With Video Plugin [FIXED]

Update: This has now been fixed and will shortly be available from the Windows Live Gallery. Do not download from the Gallery unless the version shows as 3.0.0.24 as this is the updated version. It is just pending approval at the moment.

Update 2: It is now live on Live Gallery.

It has been brought to my attention (and sadly confirmed ) that there is a slight bug in my Video Plugin for Windows Live Writer. The issue is simple, if you put more than one video into a blog entry, some of the video properties (like in the sidebar) get shared, and no matter what you set the insert method to be (full embed, image, plugin decides), it will always be the full embed code. This is something that I am now looking into and hope to have a resolution soon

SL

 
Whilst writing this I was listening to AerosmithDude (Looks Like A Lady)

9 Comments