News Viewer is a comprehensive C++ application that fetches and displays real-time news headlines from NewsAPI. Built with modern C++ features and best practices, it showcases advanced programming concepts including multithreading, STL usage, and real-time UI updates.
✔ Real-time News Fetching
- Live headlines from NewsAPI
- Background auto-updates every 5 minutes
- Smart caching system to reduce API calls
✔ Advanced User Interface
- Modern ImGui-based interface
- Dark/Light theme support
- Responsive article cards
- Rich article preview with images
- Toast notification system
✔ Search & Organization
- Keyword-based article search
- Favorites management system
- Persistent storage of user preferences
- Intelligent cache management
✔ System Architecture
- Multi-threaded design
- Thread-safe data handling
- Robust error handling
- Efficient memory management
// Vector management for articles
std::vector<NewsArticle> articles;
// Efficient caching with unordered_map
std::unordered_map<std::string, std::vector<NewsArticle>> searchCache;
// File operations with filesystem
namespace fs = std::filesystem;
if (fs::exists(CACHE_FILE)) {
// Cache handling
}
// Background update thread
std::thread updateThread;
std::atomic<bool> isAutoUpdateRunning{false};
// Thread-safe operations
std::mutex fetchMutex;
std::lock_guard<std::mutex> lock(fetchMutex);
- Intelligent caching with 1-hour expiry
- Reduces API calls and improves responsiveness
- Thread-safe implementation
const time_t CACHE_EXPIRY = 60 * 60; // 1 Hour cache expiry
bool isCacheExpired(const std::string& keyword);
- Comprehensive error catching and logging
- Graceful degradation on API failures
- User-friendly error messages
try {
headlines = fetcher.fetchHeadlines();
} catch (const std::exception& e) {
showMessage("Failed to load headlines", colors.error);
}
📦 NewsViewer
┣ 📂 src/
┃ ┣ 📜 main.cpp # Application entry
┃ ┣ 📜 news_fetcher.cpp # API & cache management
┃ ┣ 📜 news_storage.cpp # Data persistence
┃ ┗ 📜 ui.cpp # User interface
┣ 📂 include/
┃ ┣ 📜 news_fetcher.h # API declarations
┃ ┣ 📜 news_storage.h # Storage declarations
┃ ┗ 📜 ui.h # UI declarations
┣ 📂 assets/ # Application resources
┗ 📜 CMakeLists.txt # Build configuration
- C++17 compiler
- CMake 3.14+
- OpenGL & GLFW
- OpenSSL
- ImGui - UI framework
- httplib - HTTP client
- nlohmann/json - JSON parsing
- STL - Core functionality
# Clone the repository
git clone https://github.com/HananelSabag/NewsViewerCpp.git
cd NewsViewerCpp
# Create build directory
mkdir build && cd build
# Configure and build
cmake ..
make
# Run the application
./NewsViewer
- Handles API communication
- Implements caching logic
- Manages background updates
- Ensures thread safety
- Manages favorites system
- Handles data persistence
- Implements file I/O
- Validates data integrity
- ImGui-based rendering
- Theme management
- Popup system
- Image loading and caching
- Toast notifications
-
Main Thread
- UI rendering
- User interaction
- Event handling
-
Update Thread
- Background fetching
- Cache management
- API communication
-
Image Loading Thread
- Asynchronous image loading
- Memory management
- Error handling
struct CacheEntry {
std::vector<NewsArticle> articles;
std::time_t timestamp;
};
std::unordered_map<std::string, CacheEntry> searchCache;
- Smart caching with expiry
- Memory-efficient storage
- Thread-safe access
🔹 Local offline storage
🔹 Advanced search filters
🔹 Multiple news sources
🔹 Custom theme editor
🔹 Analytics dashboard
-
Hananel Sabag
- Core architecture
- Threading implementation
- UI development
-
Amit Cohen
- Data management
- Cache system
- Error handling
This project was developed as part of the Advanced C++ course at JCE (Jerusalem College of Engineering), supervised by Mr. Harel Welch.
✅ STL Implementation
✅ Thread Management
✅ UI Development
✅ Error Handling
✅ Modern C++ Features
✅ Third-party Library Integration
This project is licensed under the MIT License - see the LICENSE file for details.