Initial checkin of IE-compatible favorites plugin

import/tags/kmeleon03
binaryc 22 years ago
parent a1f21bb2ad
commit a8adff3315
  1. 8
      k-meleon/ie_favorites/StdAfx.cpp
  2. 27
      k-meleon/ie_favorites/StdAfx.h
  3. 287
      k-meleon/ie_favorites/ie_favorites.cpp
  4. 120
      k-meleon/ie_favorites/ie_favorites.dsp

@ -0,0 +1,8 @@
// stdafx.cpp : source file that includes just the standard includes
// ie_favorites.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file

@ -0,0 +1,27 @@
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__DC17800A_F904_11D4_AA28_00E02916DA72__INCLUDED_)
#define AFX_STDAFX_H__DC17800A_F904_11D4_AA28_00E02916DA72__INCLUDED_
// Insert your headers here
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <afxwin.h> // MFC core and standard components
#include <afxtempl.h>
// TODO: reference additional headers your program requires here
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__DC17800A_F904_11D4_AA28_00E02916DA72__INCLUDED_)

@ -0,0 +1,287 @@
/*
* Copyright (C) 2000 Brian Harris
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// ie_favorites.cpp : Plugin that supports ie-style boomarks
//
#include "stdafx.h"
//#include "resource.h"
#define KMELEON_PLUGIN_EXPORTS
#include "../kmeleon_plugin.h"
#define MAX_FAVORITES 255
/*
// MFC handles this for us (how nice)
BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved )
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
*/
int Init();
void Config(HWND parent);
void Quit();
HGLOBAL GetMenu();
void DoMenu(HMENU menu, char *param);
void OnCommand(UINT command);
kmeleonPlugin kPlugin = {
KMEL_PLUGIN_VER,
"IE Favorites Plugin",
Init,
Config,
Quit,
DoMenu,
OnCommand
};
CMenu m_menuFavorites;
UINT nConfigCommand;
UINT nAddCommand;
UINT nFirstFavoriteCommand;
int Init(){
nFirstFavoriteCommand = kPlugin.GetCommandIDs(MAX_FAVORITES);
nConfigCommand = kPlugin.GetCommandIDs(1);
nAddCommand = kPlugin.GetCommandIDs(1);
return true;
}
void Config(HWND parent){
MessageBox(parent, "This plugin brought to you by the letter M", "IE Favorites plugin", 0);
}
void Quit(){
}
static CStringArray m_astrFavoriteURLs;
static CMap<CString, LPCTSTR, int, int> m_URLIcons;
static int m_iInternetShortcutIcon;
static HIMAGELIST m_himSystem;
static CSize m_SysImageSize;
static int m_iFolderIcon;
int BuildFavoritesMenu(LPCTSTR pszPath, int nStartPos, CMenu* pMenu)
{
CString strPath(pszPath);
CString strPath2;
CString str;
WIN32_FIND_DATA wfd;
HANDLE h;
int nPos;
int nEndPos;
int nNewEndPos;
int nLastDir;
TCHAR buf[MAX_PATH];
CStringArray astrFavorites;
CStringArray astrDirs;
CMenu* pSubMenu;
// make sure there's a trailing backslash
if(strPath[strPath.GetLength() - 1] != _T('\\'))
strPath += _T('\\');
strPath2 = strPath;
strPath += _T("*.*");
// now scan the directory, first for .URL files and then for subdirectories
// that may also contain .URL files
h = FindFirstFile(strPath, &wfd);
if(h != INVALID_HANDLE_VALUE)
{
nEndPos = nStartPos;
do
{
if((wfd.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM))==0)
{
str = wfd.cFileName;
if(str.Right(4).CompareNoCase(_T(".url")) == 0)
{
// an .URL file is formatted just like an .INI file, so we can
// use GetPrivateProfileString() to get the information we want
::GetPrivateProfileString(_T("InternetShortcut"), _T("URL"),
_T(""), buf, MAX_PATH,
strPath2 + str);
str = str.Left(str.GetLength() - 4);
// scan through the array and perform an insertion sort
// to make sure the menu ends up in alphabetic order
/*
for(nPos = nStartPos ; nPos < nEndPos ; ++nPos) {
if(str.CompareNoCase(astrFavorites[nPos]) < 0)
break;
}
*/
nPos = m_astrFavoriteURLs.GetSize();
astrFavorites.InsertAt(nPos, str);
m_astrFavoriteURLs.InsertAt(nPos, buf);
TCHAR ext[_MAX_EXT];
_tsplitpath (buf, NULL, NULL, NULL, ext);
int iIcon;
if (!m_URLIcons.Lookup (ext, iIcon))
{
// Retrieve icon file
SHFILEINFO sfi;
if (::SHGetFileInfo (strPath2 + wfd.cFileName, 0, &sfi, sizeof(SHFILEINFO),
SHGFI_SMALLICON | SHGFI_SYSICONINDEX) &&
sfi.iIcon >= 0)
{
m_URLIcons.SetAt (ext, sfi.iIcon);
if (m_iInternetShortcutIcon == -1)
{
m_iInternetShortcutIcon = sfi.iIcon;
}
}
}
++nEndPos;
}
}
} while(FindNextFile(h, &wfd));
FindClose(h);
// Now add these items to the menu
for(nPos = nStartPos ; nPos < nEndPos ; ++nPos) {
pMenu->AppendMenu(MF_STRING | MF_ENABLED, nFirstFavoriteCommand + nPos, astrFavorites[nPos]);
}
// now that we've got all the .URL files, check the subdirectories for more
nLastDir = 0;
h = FindFirstFile(strPath, &wfd);
ASSERT(h != INVALID_HANDLE_VALUE);
do
{
if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
// ignore the current and parent directory entries
if(lstrcmp(wfd.cFileName, _T(".")) == 0 || lstrcmp(wfd.cFileName, _T("..")) == 0)
continue;
/*
for(nPos = 0 ; nPos < nLastDir ; ++nPos)
{
if(astrDirs[nPos].CompareNoCase(wfd.cFileName) > 0)
break;
}*/
pSubMenu = new CMenu;
pSubMenu->CreatePopupMenu();
// call this function recursively.
nNewEndPos = BuildFavoritesMenu(strPath2 + wfd.cFileName, nEndPos, pSubMenu);
if(nNewEndPos != nEndPos) {
// only intert a submenu if there are in fact .URL files in the subdirectory
nEndPos = nNewEndPos;
//pMenu->AppendMenu(MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT)pSubMenu->m_hMenu, wfd.cFileName);
pMenu->InsertMenu(nFirstFavoriteCommand + nStartPos, MF_BYCOMMAND | MF_POPUP | MF_STRING, (UINT)pSubMenu->m_hMenu, wfd.cFileName);
pSubMenu->Detach();
astrDirs.InsertAt(nPos, wfd.cFileName);
++nLastDir;
}
delete pSubMenu;
}
} while(FindNextFile(h, &wfd));
FindClose(h);
}
return nEndPos;
}
void DoMenu(HMENU menu, char *param){
if (stricmp(param, _T("Config")) == 0){
AppendMenu(menu, MF_STRING, nConfigCommand, "&Config");
return;
}
if (stricmp(param, _T("Add")) == 0){
AppendMenu(menu, MF_STRING, nAddCommand, "&Add Favorite");
return;
}
m_menuFavorites.Attach(menu);
TCHAR sz[MAX_PATH];
TCHAR szPath[MAX_PATH];
HKEY hKey;
DWORD dwSize;
// find out from the registry where the favorites are located.
if(RegOpenKey(HKEY_CURRENT_USER, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders"), &hKey) != ERROR_SUCCESS)
{
TRACE0("Favorites folder not found\n");
//return;
strcpy(sz, _T("c:\\windows\\favorites"));
}
dwSize = sizeof(sz);
RegQueryValueEx(hKey, _T("Favorites"), NULL, NULL, (LPBYTE)sz, &dwSize);
ExpandEnvironmentStrings(sz, szPath, MAX_PATH);
RegCloseKey(hKey);
BuildFavoritesMenu(szPath, 0, &m_menuFavorites);
SHFILEINFO sfi;
m_himSystem = (HIMAGELIST)SHGetFileInfo( szPath,
0,
&sfi,
sizeof(SHFILEINFO),
SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
if (m_himSystem != NULL) {
int cx, cy;
::ImageList_GetIconSize (m_himSystem, &cx, &cy);
m_SysImageSize = CSize (cx, cy);
m_iFolderIcon = sfi.iIcon;
}
}
void OnCommand(UINT command){
if (command == nConfigCommand){
Config(NULL);
return;
}
if (command == nAddCommand){
//AppendMenu(mainMenu, MF_STRING, nFirstFavoriteCommand, "New Item");
return;
}
if (command >= nFirstFavoriteCommand && command < (nFirstFavoriteCommand + MAX_FAVORITES)){
kPlugin.NavigateTo((char *)(LPCTSTR)m_astrFavoriteURLs.GetAt(command - nFirstFavoriteCommand), 0);
}
}
// so it doesn't munge the function name
extern "C" {
KMELEON_PLUGIN kmeleonPlugin *GetKmeleonPlugin() {
return &kPlugin;
}
}

@ -0,0 +1,120 @@
# Microsoft Developer Studio Project File - Name="ie_favorites" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
CFG=ie_favorites - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "ie_favorites.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
!MESSAGE NMAKE /f "ie_favorites.mak" CFG="ie_favorites - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "ie_favorites - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE "ie_favorites - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
MTL=midl.exe
RSC=rc.exe
!IF "$(CFG)" == "ie_favorites - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
# PROP BASE Output_Dir "Release"
# PROP BASE Intermediate_Dir "Release"
# PROP BASE Target_Dir ""
# PROP Use_MFC 0
# PROP Use_Debug_Libraries 0
# PROP Output_Dir "Release"
# PROP Intermediate_Dir "Release"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "IE_FAVORITES_EXPORTS" /Yu"stdafx.h" /FD /c
# ADD CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "IE_FAVORITES_EXPORTS" /Yu"stdafx.h" /FD /c
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "NDEBUG"
# ADD RSC /l 0x409 /d "NDEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"c:/projects/mozilla/mozilla/dist/win32_o.obj/bin/kmeleon_favorites.dll"
!ELSEIF "$(CFG)" == "ie_favorites - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
# PROP BASE Output_Dir "Debug"
# PROP BASE Intermediate_Dir "Debug"
# PROP BASE Target_Dir ""
# PROP Use_MFC 1
# PROP Use_Debug_Libraries 1
# PROP Output_Dir "Debug"
# PROP Intermediate_Dir "Debug"
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "IE_FAVORITES_EXPORTS" /Yu"stdafx.h" /FD /GZ /c
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "IE_FAVORITES_EXPORTS" /D "_WINDLL" /FR /Yu"stdafx.h" /FD /GZ /c
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
# ADD BASE RSC /l 0x409 /d "_DEBUG"
# ADD RSC /l 0x409 /d "_DEBUG"
BSC32=bscmake.exe
# ADD BASE BSC32 /nologo
# ADD BSC32 /nologo
LINK32=link.exe
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
# ADD LINK32 /nologo /dll /debug /machine:I386 /out:"c:/projects/mozilla/mozilla/dist/win32_o.obj/bin/kmeleon_favorites.dll" /pdbtype:sept
!ENDIF
# Begin Target
# Name "ie_favorites - Win32 Release"
# Name "ie_favorites - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\ie_favorites.cpp
# End Source File
# Begin Source File
SOURCE=.\StdAfx.cpp
# ADD CPP /Yc"stdafx.h"
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\StdAfx.h
# End Source File
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# Begin Source File
SOURCE=.\ReadMe.txt
# End Source File
# End Target
# End Project
Loading…
Cancel
Save