示例#1
0
        public override void OK()
        {
            ISettingStore   settings   = Core.SettingStore;
            int             lastMethod = BookmarkService.DownloadMethod;
            BookmarkService service    = FavoritesPlugin._bookmarkService;

            if (_idleButton.Checked)
            {
                BookmarkService.DownloadMethod = 0;
                if (lastMethod != 0)
                {
                    service.SynchronizeBookmarks();
                }
            }
            else if (_immediateButton.Checked)
            {
                BookmarkService.DownloadMethod = 1;
                if (lastMethod != 1)
                {
                    service.SynchronizeBookmarks();
                }
            }
            else
            {
                BookmarkService.DownloadMethod = 2;
            }
            CookiesManager.SetUserCookieProviderName(typeof(FavoriteJob), _cookieProviderSelector.SelectedProfileName);
            IResource res = (IResource)_bookmarkFoldersBox.SelectedItem;

            if (res != null)
            {
                settings.WriteInt("Favorites", "CatAnnRoot", res.Id);
            }
        }
示例#2
0
        public bool ResourceRenamed(IResource res, string newName)
        {
            string oldName = res.GetStringProp(Core.Props.Name);

            if (oldName == null || newName == null || oldName == newName)
            {
                return(false);
            }
            if (newName.Length == 0 || newName == "New Folder")
            {
                MessageBox.Show(Core.MainWindow,
                                "Please specify a name.", "Rename", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }
            // check duplicates on the same level for some cases
            IBookmarkProfile profile = _bookmarkService.GetOwnerProfile(res);
            IResource        parent  = res.GetLinkProp(_propParent);

            if (parent != null && (profile == _favoritesProfile || res.Type == "Folder") &&
                BookmarkService.HasSubNodeWithName(parent, newName))
            {
                MessageBox.Show(Core.MainWindow,
                                "The name is already used, please specify another", "Rename", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return(false);
            }
            if (profile != null)
            {
                profile.Rename(res, newName);
            }
            new ResourceProxy(res).SetPropAsync(Core.Props.Name, newName);
            return(true);
        }
示例#3
0
 private IResource ForwardWeblinkDisplay(IResource resource)
 {
     if (Core.State != CoreState.Running)
     {
         return(resource);
     }
     try
     {
         string url = resource.GetPropText(_propURL);
         if (BookmarkService.DownloadMethod == 2)
         {
             if (_lastDisplayedWeblink != resource)
             {
                 BookmarkService.ImmediateQueueWeblink(resource, url);
             }
             return(resource);
         }
         Core.ResourceBrowser.ShowUrlBar(url);
         IResource source = resource.GetLinkProp("Source");
         if (source != null)
         {
             return(source);
         }
         return(resource);
     }
     finally
     {
         _lastDisplayedWeblink = resource;
     }
 }
示例#4
0
        private void NewWeblink()
        {
            bool newWeblink = false;

            if (_favorite == null)
            {
                _favorite  = Core.ResourceStore.BeginNewResource("Weblink");
                newWeblink = true;
            }
            else
            {
                _favorite.BeginUpdate();
            }
            try
            {
                string url = _URLBox.Text;
                _favorite.SetProp(Core.Props.Name, _nameBox.Text);
                _favorite.SetProp(FavoritesPlugin._propURL, url);
                int updateFreq = 0;
                if (_updateCheckBox.Checked)
                {
                    updateFreq = (int)_hoursBox.Value * 60 * 60;
                    int unitIndex = _unitBox.SelectedIndex;
                    if (unitIndex > 0)  // days or weeks
                    {
                        updateFreq *= 24;
                        if (unitIndex > 1)  // weeks
                        {
                            updateFreq *= 7;
                        }
                    }
                }
                _favorite.SetProp(FavoritesPlugin._propUpdateFreq, updateFreq);
                if (_parent != null)
                {
                    _favorite.AddLink(FavoritesPlugin._propParent, _parent);
                }
                Core.WorkspaceManager.AddToActiveWorkspace(_favorite);
            }
            finally
            {
                _favorite.EndUpdate();
            }
            if (newWeblink)
            {
                IBookmarkProfile profile = _bookmarkService.GetOwnerProfile(_favorite);
                string           error   = null;
                if (profile != null && profile.CanCreate(_favorite, out error))
                {
                    profile.Create(_favorite);
                }
                else
                {
                    Core.UserInterfaceAP.QueueJob(new LineDelegate(DisplayError), error);
                }
                BookmarkService.ImmediateQueueWeblink(_favorite, _URLBox.Text);
            }
        }
示例#5
0
 public bool AcceptLink(IResource displayedResource, int propId, IResource targetResource,
                        ref string linkTooltip)
 {
     if (propId == FavoritesPlugin._propParent && targetResource == BookmarkService.GetBookmarksRoot())
     {
         return(false);
     }
     return(true);
 }
示例#6
0
文件: FavoriteUOW.cs 项目: mo5h/omeo
        private void ProcessFile()
        {
            if (_webLink.IsDeleted)  // if favorite resource was deleted then do nothing
            {
                return;
            }
            FileInfo fileInfo   = _reader.fileInfo;
            Stream   readStream = _reader.ReadStream;

            using ( readStream )
            {
                DateTime lastWriteTime = IOTools.GetLastWriteTime(fileInfo);
                if (!_webLink.HasProp("LastModified") || lastWriteTime > LastModified() ||
                    _webLink.HasProp(Core.Props.LastError))
                {
                    bool      isShowed   = BookmarkService.BookmarkSynchronizationFrequency(_webLink) > 0;
                    IResource formatFile = _webLink.GetLinkProp("Source");
                    _webLink.BeginUpdate();
                    if (formatFile != null)
                    {
                        formatFile.BeginUpdate();
                    }
                    else
                    {
                        string resourceType = Core.FileResourceManager.GetResourceTypeByExtension(fileInfo.Extension);
                        if (resourceType == null)
                        {
                            resourceType = "UnknownFile";
                        }
                        formatFile = Core.ResourceStore.BeginNewResource(resourceType);
                        _webLink.AddLink("Source", formatFile);
                    }
                    if (_webLink.HasProp(Core.Props.LastError))
                    {
                        SetLastError(null);
                    }
                    _webLink.SetProp("LastModified", lastWriteTime);
                    formatFile.SetProp(Core.Props.Size, (int)readStream.Length);
                    formatFile.SetProp(FavoritesPlugin._propContent, readStream);
                    if (isShowed)
                    {
                        formatFile.SetProp(Core.Props.Date, lastWriteTime);
                        formatFile.SetProp(FavoritesPlugin._propIsUnread, true);
                        Core.FilterEngine.ExecRules(StandardEvents.ResourceReceived, _webLink);
                    }
                    if (formatFile.Type != "UnknownFile")
                    {
                        Core.TextIndexManager.QueryIndexing(formatFile.Id);
                    }
                    _webLink.EndUpdate();
                    formatFile.EndUpdate();
                }
            }
        }
示例#7
0
文件: OperaProfile.cs 项目: mo5h/omeo
 private void CollectAllSubNodes(IResource root, IntHashSet nodes)
 {
     if (root != _root)
     {
         nodes.Add(root.Id);
     }
     foreach (IResource child in BookmarkService.SubNodes(null, root))
     {
         CollectAllSubNodes(child, nodes);
     }
 }
示例#8
0
        public override void EnterPane()
        {
            _bookmarkFoldersBox.Items.Clear();
            _bookmarkFoldersBox.AddResourceHierarchy(
                BookmarkService.GetBookmarksRoot(), "Folder",
                FavoritesPlugin._propParent, new AcceptResourceDelegate(AcceptFolder));
            int id = Core.SettingStore.ReadInt(
                "Favorites", "CatAnnRoot", BookmarkService.GetBookmarksRoot().Id);

            _bookmarkFoldersBox.SelectedItem = Core.ResourceStore.TryLoadResource(id);
        }
示例#9
0
        public void Execute(IActionContext context)
        {
            IResourceList resources         = context.SelectedResources;
            IResource     folder            = BookmarkService.GetBookmarksRoot();
            IResource     selected          = folder;
            string        url               = context.CurrentUrl;
            bool          isWeblinkSelected = false;

            if (resources.Count > 0)
            {
                selected = resources[0];
            }
            else
            {
                if (FavoritesPlugin._favoritesTreePane.SelectedNode != null)
                {
                    selected = FavoritesPlugin._favoritesTreePane.SelectedNode;
                }
            }
            if (selected.Type == "Folder")
            {
                folder = selected;
            }
            else if (selected.Type == "Weblink")
            {
                folder            = BookmarkService.GetParent(selected);
                isWeblinkSelected = url != null && selected.GetPropText(FavoritesPlugin._propURL) == url;
            }
            else
            {
                selected = selected.GetLinkProp("Source");
                if (selected != null && selected.Type == "Weblink")
                {
                    folder            = BookmarkService.GetParent(selected);
                    isWeblinkSelected = url != null && selected.GetPropText(FavoritesPlugin._propURL) == url;
                }
            }

            using (AddFavoriteForm frm = new AddFavoriteForm(folder))
            {
                if (!isWeblinkSelected || Core.TabManager.CurrentTabId != "Web")
                {
                    if (url != null)
                    {
                        frm.SetURL(url);
                    }
                    if (context.CurrentPageTitle != null)
                    {
                        frm._nameBox.Text = context.CurrentPageTitle;
                    }
                }
                frm.ShowDialog(Core.MainWindow);
            }
        }
示例#10
0
 public bool CanDropResources(IResource targetResource, IResourceList dragResources)
 {
     if (dragResources.Count > 0)
     {
         if (targetResource != _bookmarkService.BookmarksRoot)
         {
             if (targetResource.Type != "Folder")
             {
                 return(false);
             }
             IBookmarkProfile targetProfile = _bookmarkService.GetOwnerProfile(targetResource);
             foreach (IResource dragRes in dragResources)
             {
                 string           error;
                 IBookmarkProfile sourceProfile = _bookmarkService.GetOwnerProfile(dragRes);
                 if (sourceProfile == targetProfile)
                 {
                     if (targetProfile != null && !targetProfile.CanMove(dragRes, targetResource, out error))
                     {
                         return(false);
                     }
                 }
                 else
                 {
                     if (sourceProfile != null && !sourceProfile.CanDelete(dragRes, out error))
                     {
                         return(false);
                     }
                     if (targetProfile != null && !targetProfile.CanCreate(dragRes, out error))
                     {
                         return(false);
                     }
                 }
             }
             IResource temp = targetResource;
             do
             {
                 if (dragResources.IndexOf(temp) >= 0)
                 {
                     return(false);
                 }
                 temp = BookmarkService.GetParent(temp);
             } while(temp != null);
         }
         string[] types = dragResources.GetAllTypes();
         if (types.Length < 3)
         {
             return((types[0] == "Weblink" || types[0] == "Folder") &&
                    (types.Length == 1 || types[1] == "Weblink" || types[1] == "Folder"));
         }
     }
     return(false);
 }
示例#11
0
        private void _okButton_Click(object sender, System.EventArgs e)
        {
            HashSet updatesResources = new HashSet();

            for (int i = 0; i < content.Count; ++i)
            {
                IResource webLink = content[i];
                if (webLink.Type != "Weblink" && webLink.Type != "Folder")
                {
                    webLink = webLink.GetLinkProp("Source");
                }
                updatesResources.Add(webLink);
            }

            for (int i = 0; i < content.Count; ++i)
            {
                IResource webLink = content[i];
                if (webLink.Type != "Weblink" && webLink.Type != "Folder")
                {
                    webLink = webLink.GetLinkProp("Source");
                }
                IResource parent = BookmarkService.GetParent(webLink);
                while (parent != null)
                {
                    if (content.IndexOf(parent) >= 0)
                    {
                        updatesResources.Remove(webLink);
                        break;
                    }
                    parent = BookmarkService.GetParent(parent);
                }
            }

            int updateFreq = (_updateCheckBox.Checked) ? ((int)_hoursBox.Value * 60 * 60) : 0;
            int unitIndex  = _unitBox.SelectedIndex;

            if (unitIndex > 0)
            {
                updateFreq *= 24;
                if (unitIndex > 1)
                {
                    updateFreq *= 7;
                }
            }

            foreach (HashSet.Entry E in updatesResources)
            {
                new ResourceProxy((IResource)E.Key).SetPropAsync(FavoritesPlugin._propUpdateFreq, updateFreq);
            }

            Close();
        }
示例#12
0
        private static IResourceList FindOrCreateWeblinksByUrl(string url, string title)
        {
            IResourceList weblinks = Core.ResourceStore.FindResources("Weblink", _propURL, url.Trim());

            if (weblinks.Count > 0)
            {
                return(weblinks);
            }
            int       id      = Core.SettingStore.ReadInt("Favorites", "CatAnnRoot", _bookmarkService.BookmarksRoot.Id);
            IResource annRoot = Core.ResourceStore.TryLoadResource(id) ?? _bookmarkService.BookmarksRoot;

            return(BookmarkService.FindOrCreateBookmark(annRoot, title, url, true).ToResourceList());
        }
示例#13
0
        private void EnumerateFavorites(string folder, IResource parent)
        {
            FileInfo[] files = IOTools.GetFiles(folder);
            if (files != null)
            {
                IResourceList weblinks          = BookmarkService.SubNodes("Weblink", parent);
                IntArrayList  processedWeblinks = new IntArrayList(files.Length);
                foreach (FileInfo fileInfo in files)
                {
                    IResource weblink = null;
                    try
                    {
                        if (fileInfo.Extension.ToLower() == ".url")
                        {
                            weblink = ProcessFavoriteFile(fileInfo, parent);
                        }
                        else if (fileInfo.Extension.ToLower() == ".lnk")
                        {
                            weblink = ProcessShortcut(fileInfo, parent);
                        }
                    }
                    catch (Exception e)
                    {
                        FavoritesTools.TraceIfAllowed(e.Message);
                        continue;
                    }
                    if (weblink != null)
                    {
                        processedWeblinks.Add(weblink.Id);
                    }
                }
                _bookmarkservice.DeleteBookmarks(weblinks.Minus(
                                                     Core.ResourceStore.ListFromIds(processedWeblinks, false)));
            }

            DirectoryInfo[] dirs = IOTools.GetDirectories(folder);
            if (dirs != null)
            {
                IResourceList folders          = BookmarkService.SubNodes("Folder", parent);
                IntArrayList  processedFolders = new IntArrayList(dirs.Length);
                foreach (DirectoryInfo dirInfo in dirs)
                {
                    IResource subfolder = _bookmarkservice.FindOrCreateFolder(parent, dirInfo.Name);
                    EnumerateFavorites(IOTools.GetFullName(dirInfo), subfolder);
                    processedFolders.Add(subfolder.Id);
                }
                _bookmarkservice.DeleteFolders(folders.Minus(
                                                   Core.ResourceStore.ListFromIds(processedFolders, false)));
            }
        }
示例#14
0
 public void Execute(IActionContext context)
 {
     for (int i = 0; i < context.SelectedResources.Count; ++i)
     {
         IResource res = context.SelectedResources[i];
         if (res.Type != "Weblink")
         {
             res = res.GetLinkProp("Source");
         }
         if (res != null && res.Type == "Weblink")
         {
             BookmarkService.ImmediateQueueWeblink(res, res.GetPropText("URL"));
         }
     }
 }
示例#15
0
 public void Execute(IActionContext context)
 {
     if (context.SelectedResources.Count == 0)
     {
         _parentFolder = BookmarkService.GetBookmarksRoot();
     }
     else
     {
         _parentFolder = context.SelectedResources[0];
         if (_parentFolder.Type == "Weblink")
         {
             _parentFolder = BookmarkService.GetParent(_parentFolder);
         }
     }
     Core.ResourceAP.QueueJob(JobPriority.Immediate, new MethodInvoker(NewFolder));
 }
示例#16
0
        private static bool AcceptFolder(IResource folder)
        {
            bool result = folder.GetLinksTo(null, FavoritesPlugin._propParent).Minus(
                Core.ResourceStore.FindResourcesWithProp(null, FavoritesPlugin._propInvisible)).Count > 0;

            while (result && folder != null && folder != BookmarkService.GetBookmarksRoot())
            {
                if (folder.HasProp(FavoritesPlugin._propInvisible))
                {
                    result = false;
                    break;
                }
                folder = folder.GetLinkProp(FavoritesPlugin._propParent);
            }
            return(result);
        }
示例#17
0
        /**
         * Gets full name of IE folder or favorite
         */
        public string GetResourceFullname(IResource res)
        {
            Guard.NullArgument(res, "res");
            IResource parent = res;
            IResource ieRoot = _bookmarkservice.GetProfileRoot(this);

            if (ieRoot != null)
            {
                Stack parents = new Stack();
                for ( ; ;)
                {
                    if (parent == ieRoot)
                    {
                        string fullName = Environment.GetFolderPath(Environment.SpecialFolder.Favorites);
                        while (parents.Count > 0)
                        {
                            res      = (IResource)parents.Pop();
                            fullName = IOTools.Combine(fullName, res.DisplayName);
                        }
                        if (fullName.IndexOfAny(InvalidNameChars) >= 0)
                        {
                            foreach (char invalidChar in Path.InvalidPathChars)
                            {
                                fullName = fullName.Replace(invalidChar, '-');
                            }
                        }
                        fullName = fullName.Replace("https://", null);
                        fullName = fullName.Replace("http://", null);
                        fullName = fullName.Replace("ftp://", null);
                        fullName = fullName.Replace("file://", null);
                        fullName = fullName.Replace("://", null);
                        if (res.Type != "Folder")
                        {
                            fullName += ".url";
                        }
                        return(fullName);
                    }
                    if ((parent = BookmarkService.GetParent(parent)) == null)
                    {
                        break;
                    }
                    parents.Push(res);
                    res = parent;
                }
            }
            return(string.Empty);
        }
示例#18
0
        public void Rename(IResource res, string newName)
        {
            BookmarkChange change = new BookmarkChange();

            change.type  = 0;
            change.id    = res.Id;
            change.rdfid = res.GetPropText(FavoritesPlugin._propBookmarkId);
            IResource parent = BookmarkService.GetParent(res);

            if (parent != null)
            {
                change.parent    = GetFolderBookmarkId(parent);
                change.parent_id = parent.Id;
            }
            change.name = newName;
            change.url  = res.GetPropText(FavoritesPlugin._propURL);
            LogBookmarkChange(change);
        }
示例#19
0
        private void WeblinkOrFolderChanged(object sender, ResourcePropIndexEventArgs e)
        {
            IResource webLink = e.Resource;

            IPropertyChangeSet set = e.ChangeSet;
            int propLastModified   = Core.ResourceStore.PropTypes["LastModified"].Id;

            if (BookmarkService.DownloadMethod != 2 && webLink == _lastDisplayedWeblink &&
                ((set.IsPropertyChanged(propLastModified) && webLink.HasProp("Source")) ||
                 (set.IsPropertyChanged(Core.Props.LastError) && webLink.HasProp(Core.Props.LastError))))
            {
                // if the displayed web link has changed, redisplay it
                IResourceBrowser browser = Core.ResourceBrowser;
                if ((webLink == _favoritesTreePane.SelectedNode && Core.TabManager.CurrentTabId == "Web") ||
                    (browser.SelectedResources.Count == 1 && webLink == browser.SelectedResources[0]))
                {
                    Core.UserInterfaceAP.QueueJobAt(DateTime.Now.AddSeconds(1), "RedisplaySelectedResource", browser.RedisplaySelectedResource);
                }
            }

            string URL = webLink.GetPropText(_propURL);

            if (URL.Length > 0)
            {
                if (set.IsPropertyChanged(_propLastUpdated) || set.IsPropertyChanged(_propUpdateFreq))
                {
                    BookmarkService.QueueWeblink(webLink, URL, BookmarkService.BookmarkSynchronizationTime(webLink));
                }
                if (set.IsPropertyChanged(_propURL))
                {
                    BookmarkService.ImmediateQueueWeblink(webLink, URL);
                }
            }
            if (set.IsPropertyChanged(Core.PropIds.Name) || set.IsPropertyChanged(_propURL))
            {
                IBookmarkProfile profile = _bookmarkService.GetOwnerProfile(webLink);
                string           error;
                if (profile != null && profile.CanCreate(webLink, out error))
                {
                    profile.Create(webLink);
                }
            }
        }
示例#20
0
        bool IResourceNodeFilter.AcceptNode(IResource res, int level)
        {
            if (res.HasProp(FavoritesPlugin._propInvisible))
            {
                return(false);
            }
            IBookmarkService service =
                (IBookmarkService)Core.PluginLoader.GetPluginService(typeof(IBookmarkService));

            if (service != null)
            {
                IBookmarkProfile profile = service.GetOwnerProfile(res);
                if (profile is FakeRestrictProfile)
                {
                    return(BookmarkService.SubNodes("Folder", res).Minus(
                               Core.ResourceStore.FindResourcesWithProp(null, FavoritesPlugin._propInvisible)).Count > 0);
                }
            }
            return(true);
        }
示例#21
0
        private static BookmarkChange[] ParseChangesLog(string profileName)
        {
            IBookmarkService service =
                (IBookmarkService)Core.PluginLoader.GetPluginService(typeof(IBookmarkService));
            IResource profileRoot = service.GetProfileRoot(
                BookmarkService.NormalizeProfileName("Mozilla/" + profileName));

            if (profileRoot != null)
            {
                Trace.WriteLine("ParseChangesLog( " + profileName + " ) : profileRoot != null");
                MozillaBookmarkProfile profile =
                    service.GetOwnerProfile(profileRoot) as MozillaBookmarkProfile;
                if (profile != null)
                {
                    Trace.WriteLine("ParseChangesLog( " + profileName + " ) : profile != null");
                    profile.IsActive = true;
                    IStringList log = profileRoot.GetStringListProp(_propChangesLog);
                    if (log.Count > 0)
                    {
                        Trace.WriteLine("ParseChangesLog( " + profileName + " ) : log.Count > 0");
                        BookmarkChange[] result = new BookmarkChange[log.Count];
                        for (int i = 0; i < result.Length; ++i)
                        {
                            string[] changeFields = log[i].Split('\x01');
                            result[i].type         = Int32.Parse(changeFields[0]);
                            result[i].id           = Int32.Parse(changeFields[1]);
                            result[i].rdfid        = changeFields[2];
                            result[i].oldparent    = changeFields[3];
                            result[i].oldparent_id = Int32.Parse(changeFields[4]);
                            result[i].parent       = changeFields[5];
                            result[i].parent_id    = Int32.Parse(changeFields[6]);
                            result[i].name         = changeFields[7];
                            result[i].url          = changeFields[8];
                        }
                        profileRoot.DeleteProp(_propChangesLog);
                        return(result);
                    }
                }
            }
            return(null);
        }
示例#22
0
        public void ResourcesDropped(IResource targetResource, IResourceList droppedResources)
        {
            IBookmarkProfile targetProfile = _bookmarkService.GetOwnerProfile(targetResource);

            foreach (IResource dropRes in droppedResources)
            {
                IResource        oldParent     = BookmarkService.GetParent(dropRes);
                IBookmarkProfile sourceProfile = _bookmarkService.GetOwnerProfile(dropRes);
                if (sourceProfile == targetProfile)
                {
                    if (targetProfile != null)
                    {
                        targetProfile.Move(dropRes, targetResource, oldParent);
                    }
                    new ResourceProxy(dropRes).SetProp(_propParent, targetResource);
                }
                else
                {
                    if (sourceProfile != null)
                    {
                        sourceProfile.Delete(dropRes);
                    }
                    new ResourceProxy(dropRes).SetProp(_propParent, targetResource);
                    if (targetProfile != null)
                    {
                        targetProfile.Create(dropRes);
                    }
                }
                // the resource may have been moved from a parent which belonged to a workspace
                // to the top level (#5066)
                if (dropRes.Type == "Weblink")
                {
                    Core.WorkspaceManager.AddToActiveWorkspace(dropRes);
                }
                else
                {
                    Core.WorkspaceManager.AddToActiveWorkspaceRecursive(dropRes);
                }
            }
        }
示例#23
0
        public void RemoteRefreshBookmarks(string profilePath)
        {
            string profileName = ProfilePath2Name(profilePath);

            if (profileName != null)
            {
                IBookmarkService service =
                    (IBookmarkService)Core.PluginLoader.GetPluginService(typeof(IBookmarkService));
                IResource profileRoot = service.GetProfileRoot(
                    BookmarkService.NormalizeProfileName("Mozilla/" + profileName));
                if (profileRoot != null)
                {
                    MozillaBookmarkProfile profile =
                        service.GetOwnerProfile(profileRoot) as MozillaBookmarkProfile;
                    if (profile != null)
                    {
                        profile.IsActive = true;
                        Core.ResourceAP.QueueJob(
                            "Refreshing bookmarks for " + profileName, new MethodInvoker(profile.StartImport));
                    }
                }
            }
        }
示例#24
0
        public void DisplayResource(IResource resource)
        {
            string url = resource.GetPropText(_propURL);

            if (BookmarkService.DownloadMethod == 2)
            {
                if (Core.WebBrowser.CurrentUrl != url)
                {
                    Core.WebBrowser.NavigateInPlace(url);
                    Core.ResourceBrowser.ShowUrlBar(url);
                }
            }
            else
            {
                IResource source = resource.GetLinkProp("Source");
                if (source == null)
                {
                    string lastError = resource.GetPropText(Core.Props.LastError);
                    if (lastError.Length == 0)
                    {
                        if (url.Length > 0)
                        {
                            Core.WebBrowser.ShowHtml("<html><body>Downloading...</body></html>", WebSecurityContext.Trusted, null);
                            BookmarkService.ImmediateQueueWeblink(resource, url);
                        }
                    }
                    else
                    {
                        string err = lastError.Replace("&", "&amp;").Replace("\"", "&quot;").Replace("<", "&lt;").Replace(">", "&gt;");
                        Core.WebBrowser.ShowHtml(
                            "<html><body><b>Bookmark could not be downloaded</b><br><br>" +
                            err + "</body></html>", WebSecurityContext.Trusted, null);
                    }
                }
            }
        }
示例#25
0
文件: FavoriteUOW.cs 项目: mo5h/omeo
        private void ProcessWebLink()
        {
            Stream readStream = _reader.ReadStream;

            if (readStream == null || _webLink.IsDeleted)  // if favorite resource was deleted then do nothing
            {
                return;
            }
            int             propContent = FavoritesPlugin._propContent;
            HttpWebResponse response    = _reader.WebResponse;
            // check whether http stream differs from earlier saved one
            bool differs = true;

            ///////////////////////////////////////////////////////////////////////////////
            /// the following if statement is a workaround over invalid processing by
            /// HttpReader the Not-Modified-Since header. .NET 1.1 was throwing the
            /// exception if content not modified, .NET 1.1 SP1 just returns empty stream
            ///////////////////////////////////////////////////////////////////////////////
            if (readStream.Length == 0 && !_webLink.HasProp(Core.Props.LastError))
            {
                return;
            }

            IResource formatFile = _webLink.GetLinkProp("Source");

            if (formatFile != null && formatFile.HasProp(propContent))
            {
                Stream savedStream = formatFile.GetBlobProp(propContent);
                using ( savedStream )
                {
                    if (savedStream.Length == readStream.Length)
                    {
                        differs = false;
                        for (int i = 0; i < readStream.Length; ++i)
                        {
                            if (( byte )savedStream.ReadByte() != ( byte )readStream.ReadByte())
                            {
                                readStream.Position = 0;
                                differs             = true;
                                break;
                            }
                        }
                    }
                }
            }
            if (differs)
            {
                DateTime lastModified = GetLastModified(response);
                bool     isShowed     = BookmarkService.BookmarkSynchronizationFrequency(_webLink) > 0;
                // content changed, so set properties and proceed with indexing

                string resourceType = "UnknownFile";
                if (!String.IsNullOrEmpty(response.ContentType))
                {
                    resourceType = (Core.FileResourceManager as FileResourceManager).GetResourceTypeByContentType(response.ContentType);
                    if (resourceType == null)
                    {
                        resourceType = "UnknownFile";
                    }
                }
                _webLink.BeginUpdate();
                if (formatFile != null)
                {
                    formatFile.BeginUpdate();
                    if (resourceType != "UnknownFile" && formatFile.Type != resourceType)
                    {
                        formatFile.ChangeType(resourceType);
                    }
                }
                else
                {
                    formatFile = Core.ResourceStore.BeginNewResource(resourceType);
                    _webLink.AddLink("Source", formatFile);
                }
                if (_webLink.HasProp(Core.Props.LastError))
                {
                    SetLastError(null);
                }
                _webLink.SetProp("LastModified", lastModified);
                string redirectedUrl = _reader.RedirectUrl;
                if (redirectedUrl != null && redirectedUrl.Length > 0)
                {
                    _webLink.SetProp(FavoritesPlugin._propURL, redirectedUrl);
                }
                if (_reader.ETag.Length > 0)
                {
                    _webLink.SetProp(FavoritesPlugin._propETag, _reader.ETag);
                }
                // try to get charset from content-type or from content itself
                string charset = _reader.CharacterSet;
                if (charset != null)
                {
                    _webLink.SetProp(Core.FileResourceManager.PropCharset, charset);
                }
                formatFile.SetProp(Core.Props.Size, (int)readStream.Length);
                formatFile.SetProp(propContent, readStream);
                if (isShowed)
                {
                    formatFile.SetProp(Core.Props.Date, lastModified);
                    formatFile.SetProp(FavoritesPlugin._propIsUnread, true);
                    Core.FilterEngine.ExecRules(StandardEvents.ResourceReceived, _webLink);
                }
                if (formatFile.Type != "UnknownFile")
                {
                    Core.TextIndexManager.QueryIndexing(formatFile.Id);
                }
                _webLink.EndUpdate();
                formatFile.EndUpdate();
            }
        }
示例#26
0
        private void CollectBookmarks(IResource parentFolder, MozillaBookmark[] bookmarks, ref int index, int level)
        {
            Guard.NullArgument(parentFolder, "parentFolder");

            if (index >= bookmarks.Length)
            {
                return;
            }
            HashMap       weblinks = new HashMap(); // urls 2 resources
            HashMap       folders  = new HashMap(); // folder names 2 resources
            IResourceList childs   = BookmarkService.SubNodes(null, parentFolder);

            // at first, collect all child folders and bookmarks
            foreach (IResource child in childs.ValidResources)
            {
                string id = child.GetPropText(FavoritesPlugin._propBookmarkId);
                if (id.Length > 0)
                {
                    if (child.Type == "Folder")
                    {
                        folders[id] = child;
                    }
                    else if (child.Type == "Weblink")
                    {
                        weblinks[id] = child;
                    }
                    else
                    {
                        child.DeleteLink(FavoritesPlugin._propParent, parentFolder);
                    }
                }
            }

            // look through folders and bookmarks on current level and. recursively, on sub-levels
            while (index < bookmarks.Length)
            {
                MozillaBookmark bookmark = bookmarks[index];
                if (bookmark.Level < level)
                {
                    break;
                }
                level = bookmark.Level;
                ++index;
                string id = bookmark.Id;
                if (bookmark.IsFolder)
                {
                    IResource folder = (IResource)folders[id];
                    if (folder == null)
                    {
                        folder = _bookmarkservice.FindOrCreateFolder(parentFolder, bookmark.Folder);
                    }
                    else
                    {
                        folders.Remove(id);
                        _bookmarkservice.SetName(folder, bookmark.Folder);
                        _bookmarkservice.SetParent(folder, parentFolder);
                    }
                    folder.SetProp(FavoritesPlugin._propBookmarkId, id);
                    CollectBookmarks(folder, bookmarks, ref index, level + 1);
                }
                else
                {
                    string    url     = bookmark.Url;
                    IResource weblink = (IResource)weblinks[id];
                    if (weblink == null)
                    {
                        weblink = _bookmarkservice.FindOrCreateBookmark(parentFolder, bookmark.Name, url);
                    }
                    else
                    {
                        weblinks.Remove(id);
                        _bookmarkservice.SetName(weblink, bookmark.Name);
                        _bookmarkservice.SetUrl(weblink, url);
                        _bookmarkservice.SetParent(weblink, parentFolder);
                    }
                    if (weblink != null && bookmark.Description != null && bookmark.Description.Length > 0)
                    {
                        weblink.SetProp("Annotation", bookmark.Description);
                    }
                    weblink.SetProp(FavoritesPlugin._propBookmarkId, id);
                }
            }
            // look through obsolete folders and bookmarks, delete them
            foreach (HashMap.Entry E in folders)
            {
                _bookmarkservice.DeleteFolder((IResource)E.Value);
            }
            foreach (HashMap.Entry E in weblinks)
            {
                _bookmarkservice.DeleteBookmark((IResource)E.Value);
            }
        }
示例#27
0
        public void Register()
        {
            _bookmarkService = new BookmarkService();

            RegisterTypes();

            IUIManager uiMgr = Core.UIManager;

            uiMgr.RegisterWizardPane("Import Bookmarks", ImportBookmarksOptionsPane.StartupWizardPaneCreator, 1);
            uiMgr.RegisterOptionsGroup("Internet", "The Internet options enable you to control how [product name] works with several types of online content.");
            OptionsPaneCreator favoritesPaneCreator = FavoritesOptionsPane.FavoritesOptionsPaneCreator;

            uiMgr.RegisterOptionsPane("Internet", "Favorites", favoritesPaneCreator,
                                      "The Favorites options enable you to control how your Internet Explorer Favorites are imported and synchronized with Internet Explorer.");
            ImportBookmarksOptionsPane.AddPane(favoritesPaneCreator);

            if (OperaBookmarkProfile.OperaBookmarksPath().Length > 0)
            {
                OptionsPaneCreator operaPaneCreator = OperaOptionsPane.CreatePane;
                uiMgr.RegisterOptionsPane("Internet", "Opera Bookmarks", operaPaneCreator,
                                          "The Opera Bookmarks options enable you to control how your Opera Bookmarks are imported.");
                ImportBookmarksOptionsPane.AddPane(operaPaneCreator);
            }

            OptionsPaneCreator downloadOptionsPaneCreator = DownloadOptionsPane.DownloadOptionsPaneCreator;

            uiMgr.RegisterOptionsPane("Internet", "Web Pages", downloadOptionsPaneCreator,
                                      "The Web Pages options enable you to control how your bookmarked Web pages are downloaded.");
            IPropTypeCollection propTypes = Core.ResourceStore.PropTypes;
            int sourceId = propTypes["Source"].Id;

            propTypes.RegisterDisplayName(sourceId, "Web Bookmark");
            Core.TabManager.RegisterResourceTypeTab("Web", "Web", new[] { "Weblink", "Folder" }, sourceId, 4);
            uiMgr.RegisterResourceLocationLink("Weblink", _propParent, "Folder");
            uiMgr.RegisterResourceLocationLink("Folder", _propParent, "Folder");
            uiMgr.RegisterResourceSelectPane("Weblink", typeof(ResourceTreeSelectPane));
            Core.WorkspaceManager.RegisterWorkspaceType("Weblink",
                                                        new[] { Core.ResourceStore.PropTypes["Source"].Id }, WorkspaceResourceType.Container);
            Core.WorkspaceManager.RegisterWorkspaceFolderType("Folder", "Weblink", new[] { _propParent });
            IPluginLoader loader = Core.PluginLoader;

            loader.RegisterResourceDisplayer("Weblink", this);
            loader.RegisterStreamProvider("Weblink", this);
            loader.RegisterResourceUIHandler("Folder", this);
            loader.RegisterResourceUIHandler("Weblink", this);
            loader.RegisterResourceTextProvider(null, this);
            _favIconManager = (FavIconManager)Core.GetComponentImplementation(typeof(FavIconManager));

            Image img = Utils.TryGetEmbeddedResourceImageFromAssembly(Assembly.GetExecutingAssembly(), "Favorites.Icons.Favorites24.png");

            _favoritesTreePane = Core.LeftSidebar.RegisterResourceStructureTreePane("Favorites", "Web", "Bookmarks", img, "Weblink");
            _favoritesTreePane.WorkspaceFilterTypes = new[] { "Weblink", "Folder" };
            _favoritesTreePane.EnableDropOnEmpty(this);
            JetResourceTreePane realPane = (JetResourceTreePane)_favoritesTreePane;

            realPane.AddNodeDecorator(new WeblinkNodeDecorator());
            realPane.AddNodeFilter(new BookmarkProfileFilter());
            _favoritesTreePane.ToolTipCallback = DisplayWeblinkError;
            Core.LeftSidebar.RegisterViewPaneShortcut("Favorites", Keys.Control | Keys.Alt | Keys.B);

            Core.ResourceIconManager.RegisterResourceIconProvider("Weblink", this);
            Core.ResourceIconManager.RegisterPropTypeIcon(Core.ResourceStore.PropTypes["Source"].Id, LoadIconFromAssembly("favorites1.ico"));
            _emptyWeblinkIcon = LoadIconFromAssembly("weblink_empty.ico");
            _errorWeblinkIcon = LoadIconFromAssembly("weblink_error.ico");
            WebLinksPaneFilter filter = new WebLinksPaneFilter();

            Core.ResourceBrowser.RegisterLinksPaneFilter("Weblink", filter);
            Core.ResourceBrowser.RegisterLinksPaneFilter("Folder", filter);
            Core.ResourceBrowser.RegisterResourceDisplayForwarder("Weblink", ForwardWeblinkDisplay);
            Core.FilterEngine.RegisterRuleApplicableResourceType("Weblink");

            Core.RemoteControllerManager.AddRemoteCall("Favorites.ExportMozillaBookmarkChanges.1",
                                                       new RemoteExportMozillaBookmarkChangesDelegate(RemoteExportMozillaBookmarkChanges));
            Core.RemoteControllerManager.AddRemoteCall("Favorites.SetMozillaBookmarkId.1",
                                                       new RemoteSetMozillaBookmarkIdDelegate(RemoteSetMozillaBookmarkId));
            Core.RemoteControllerManager.AddRemoteCall("Favorites.RefreshMozillaBookmarks.1",
                                                       new RemoteRefreshBookmarksDelegate(RemoteRefreshBookmarks));
            Core.RemoteControllerManager.AddRemoteCall("Favorites.AnnotateWeblink.1",
                                                       new RemoteAnnotateWeblinkDelegate(RemoteAnnotateWeblink));

            Core.DisplayColumnManager.RegisterDisplayColumn("Weblink", 0,
                                                            new ColumnDescriptor(new[] { "Name", "DisplayName" }, 300, ColumnDescriptorFlags.AutoSize));
            Core.DisplayColumnManager.RegisterDisplayColumn("Weblink", 1, new ColumnDescriptor("LastUpdated", 120));

            /**
             * bookmark profiles
             */
            Core.PluginLoader.RegisterPluginService(_bookmarkService);
            _favoritesProfile = new IEFavoritesBookmarkProfile(_bookmarkService);
            _bookmarkService.RegisterProfile(_favoritesProfile);
            if (OperaBookmarkProfile.OperaBookmarksPath().Length > 0)
            {
                _operaProfile = new OperaBookmarkProfile(_bookmarkService);
                _bookmarkService.RegisterProfile(_operaProfile);
            }
            if (MozillaProfiles.PresentOnComputer)
            {
                OptionsPaneCreator mozillaPaneCreator = MozillaOptionsPane.MozillaOptionsPaneCreator;
                uiMgr.RegisterOptionsPane("Internet", "Mozilla Bookmarks", mozillaPaneCreator,
                                          "The Mozilla Bookmarks options enable you to select Mozilla or Firefox profile which bookmarks are imported.");
                ImportBookmarksOptionsPane.AddPane(mozillaPaneCreator);
                RegisterMozillaProfiles(MozillaProfiles.GetMozillaProfiles());
                RegisterMozillaProfiles(MozillaProfiles.GetFirefoxProfiles());
                RegisterMozillaProfiles(MozillaProfiles.GetFirefox09Profiles());
                RegisterMozillaProfiles(MozillaProfiles.GetAbsoluteFirefoxProfiles());
                MozillaBookmarkProfile.SetImportPropertiesOfProfiles();
            }
        }